DevExpress v21.2新版发布会·诚邀参与

DevExpress控件使用交流,DevExpress中国社区Dev联系电话 联系电话:023-68661681

如何在XtraTreelist的每个单元格中添加下拉列表

来源:DevExpress   发布时间:2013-02-21   浏览:3850次

问题描述:

我正在用Dev的Treelist控件,现在我想在Variancy indicator Column的每个单元格中都添加一个下拉列表,示例代码如下:

[C#]Open in popup window
public partial class Scorecard : DevExpress.XtraEditors.XtraForm
    {
        public Scorecard()
        {
            InitializeComponent();
        }

        private void Scorecard_Load(object sender, EventArgs e)
        {
            CreateColumn(treeList1);
            CreateNode(treeList1);
        }

        private void CreateColumn(TreeList tl)
        {
            Variancy vari = new Variancy();
            tl.BeginUpdate();
            #region selction
            /*tl.Columns.Add();
            tl.Columns[0].Caption = "Perspektif";
            tl.Columns[0].FieldName = "perspektif";
            tl.Columns[0].UnboundType = UnboundColumnType.String;
            tl.Columns[0].VisibleIndex = 0;
            tl.Columns[0].Format.FormatType = DevExpress.Utils.FormatType.None;
            tl.Columns[0].Name = "Perspektif";

            tl.Columns.Add();
            tl.Columns[1].Caption = "Keys Performance Indicator";
            tl.Columns[1].FieldName = "KPI";
            tl.Columns[1].UnboundType = UnboundColumnType.String;
            tl.Columns[1].VisibleIndex = 1;
            tl.Columns[1].Format.FormatType = DevExpress.Utils.FormatType.Custom;
            tl.Columns[1].Name = "KPI";

            tl.Columns.Add();
            tl.Columns[2].FieldName = "VI";
            tl.Columns[2].Caption = "Variance Indicator";
            tl.Columns[2].UnboundType = UnboundColumnType.String;
            tl.Columns[2].Name = "VI";
            tl.Columns[2].Format.FormatType = DevExpress.Utils.FormatType.Custom;
            tl.Columns[2].VisibleIndex = 2;

            tl.Columns.Add();
            tl.Columns[3].FieldName = "Mat";
            tl.Columns[3].Caption = "Matrix";
            tl.Columns[3].UnboundType = UnboundColumnType.String;
            tl.Columns[3].Name = "Mat";
            tl.Columns[3].Format.FormatType = DevExpress.Utils.FormatType.Custom;
            tl.Columns[3].VisibleIndex = 3;

            tl.Columns.Add();
            tl.Columns[4].FieldName = "Weight";
            tl.Columns[4].Caption = "Weight";
            tl.Columns[4].UnboundType = UnboundColumnType.String;
            tl.Columns[4].Name = "Weight";
            tl.Columns[4].Format.FormatType = DevExpress.Utils.FormatType.Custom;
            tl.Columns[4].VisibleIndex = 4;
            tl.Columns[4].SummaryFooter = SummaryItemType.Sum;

            tl.Columns.Add();
            tl.Columns[5].FieldName = "Freq";
            tl.Columns[5].Caption = "Frequency";
            tl.Columns[5].UnboundType = UnboundColumnType.String;
            tl.Columns[5].Name = "Freq";
            tl.Columns[5].Format.FormatType = DevExpress.Utils.FormatType.Custom;
            tl.Columns[5].VisibleIndex = 5;

            tl.Columns.Add();
            tl.Columns[6].FieldName = "Baseline";
            tl.Columns[6].Caption = "Baseline";
            tl.Columns[6].UnboundType = UnboundColumnType.String;
            tl.Columns[6].Name = "Baseline";
            tl.Columns[6].Format.FormatType = DevExpress.Utils.FormatType.Custom;
            tl.Columns[6].VisibleIndex = 6;
            */
            #endregion
            string[] caption = { "Pespektif", "Variancy Indicator", "Matrix", "Weight", "Baseline", "Q1", "Q2", "Q3", "Q4",
                               "Q1", "Q2", "Q3", "Q4"};
                for (int i = 0; i < 13; i++) 
                {
                    tl.Columns.Add();
                    tl.Columns[i].Caption = caption[i];
                    tl.Columns[i].VisibleIndex = i;
                    tl.Columns[i].FieldName = caption[i];
                    tl.Columns[i].Name = caption[i];
                    tl.Columns[i].BestFit();
                    if ((i == 1) || (i == 2) || (i == 0))
                    {
                        tl.Columns[i].UnboundType = UnboundColumnType.String;
                    }
                    else {
                        tl.Columns[i].UnboundType = UnboundColumnType.Decimal;
                        tl.Columns[i].SummaryFooter = SummaryItemType.Sum;
                    }
                    tl.ExpandAll();


                 }
               
            tl.EndUpdate();
                      
        }

        private void CreateNode(TreeList tl)
        {
            tl.BeginUnboundLoad();
            // Create a root node
            TreeListNode parentForRootNodes = null;
            TreeListNode rootNode = tl.AppendNode(new object[] {"Financial"}, parentForRootNodes);
            // Create a child for a root Node
            tl.AppendNode(new object[] { "Division Budget Variance" }, rootNode);
            tl.AppendNode(new object[] { "Training Cost Per Employee" }, rootNode);
            

            TreeListNode rootNode2 = tl.AppendNode(new object[] { "Customer" }, parentForRootNodes);
            tl.AppendNode(new object[] { "Compensation Scheme Gap" }, rootNode2);
            
            TreeListNode rootNode3 = tl.AppendNode(new object[] { "Internal Busniess" }, parentForRootNodes);
            tl.AppendNode(new object[] { "Develpt. Of Manual/Processes" }, rootNode3);
            
            TreeListNode rootNode4 = tl.AppendNode(new object[] { "Learning And Growth" }, parentForRootNodes);
            tl.AppendNode(new object[] { "Training Mandays Per Employee" }, rootNode4);
            
            tl.EndUnboundLoad();
        }

        void treeList1_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                TreeListHitInfo hi = treeList1.CalcHitInfo(new Point(e.X, e.Y));
                TreeListNode newnode = treeList1.AppendNode(new object[] { "New indicator" }, hi.Node);
                treeList1.ExpandAll();
            }
        }

      
      
    }

解决方法:

要在Treelist的每个单元格中添加下拉列表,只需设置TreeListColumn.ColumnEdit属性即可

本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/470.html

联系我们
  • 重庆总部 023-68661681 400-700-1020
购买
  • sales@evget.com
合作
  • business@evget.com


在线
客服
在线
QQ
电话
咨询
023-68661681
返回
顶部