日期:2014-05-17  浏览次数:20850 次

Dotnetbar中的一个问题?
最近在研究Dotnetbar,可是有一个问题让人很郁闷。
直接拖拽一个DataGridViewX到窗体中,禁用DataGridViewX自带的 添加,删除,修改功能,后台写入下以下代码:
在最后一行中ButtonX的值总是不能显示,如果把 
DataGridViewButtonXColumn column3 = new DataGridViewButtonXColumn(); 替换成
DataGridViewButtonColumn column3 = new DataGridViewButtonColumn(); 就能显示。我真郁闷的要死。有谁用过这个,帮下忙了。我现在的目的是不要 添加,删除,修改的功能,只需要让这个DataGridViewX展示数据就够了。让他把最后一行的那个ButtonX的值显示上去!谢谢了。
C# code

        /// <summary>
        /// 初始化实时DataGridViewX
        /// </summary>
        public void LoadFmMainRealTime(DataGridViewX dLvRealTime)
        {
            //
            // 初始化列
            //
            DataGridViewTextBoxColumn column1 = new DataGridViewTextBoxColumn();
            DataGridViewTextBoxColumn column2 = new DataGridViewTextBoxColumn();
            DataGridViewButtonXColumn column3 = new DataGridViewButtonXColumn();
            DataGridViewTextBoxColumn column4 = new DataGridViewTextBoxColumn();
            column1.Width = 100;
            column1.DataPropertyName = "bh";
            column1.HeaderText = "编号";
            column2.Width = 150;
            column2.DataPropertyName = "zxshk";
            column2.HeaderText = "执行时刻";
            column3.Width = 250;
            column3.HeaderText = "描述";
            column3.DataPropertyName = "msh";
            column4.Width = 524;
            column4.Name = "info";
            column4.DataPropertyName = "xx";
            column4.HeaderText = "信息";
            dLvRealTime.Columns.AddRange(new DataGridViewColumn[] { column1, column2, column3, column4 });
            Rectangle ScreenArea = System.Windows.Forms.Screen.GetWorkingArea(dLvRealTime);
            dLvRealTime.Columns["info"].Width = ScreenArea.Width - 570;
            //
            // 初始化数据
            //
            table = new DataTable("DemoTable");
            table.Columns.Add(new DataColumn("bh") { DataType = System.Type.GetType("System.Int32") });
            table.Columns.Add(new DataColumn("zxshk"));
            table.Columns.Add(new DataColumn("msh"));
            table.Columns.Add(new DataColumn("xx"));
            for (int i = 0; i < 11; i++)
            {
                row = table.NewRow();
                row[0] = i + 1;
                row[1] = DateTime.Now.AddDays(i).ToString("yyy-MM-dd hh:mm:ss.fff");
                if (i % 2 != 0)
                    row[2] = "莱昂纳多进入";
                else if (i % 2 == 0)
                    row[2] = "莱昂纳多出去";
                row[3] = "刷卡验证";
                table.Rows.Add(row);
            }
            dataSet.Tables.Add(table);
            bindingSource.DataMember = "DemoTable";

            DataGridViewButtonXColumn bcx = dLvRealTime.Columns[2] as DataGridViewButtonXColumn;
            if (bcx != null)
            {
                bcx.UseColumnTextForButtonValue = false;
                bcx.BeforeCellPaint += Demo_BeforeCellPaint;
            }
        }

        private void Demo_BeforeCellPaint(object sender, BeforeCellPaintEventArgs e)
        {
            DataGridViewButtonXColumn bcx = sender as DataGridViewButtonXColumn;
            if (bcx != null)
            {
                if (bcx.Text == "莱昂纳多进入")
                    bcx.Image = new Bitmap(Application.StartupPath + @"\Images\arrow_down.gif");
                else if (bcx.Text == "莱昂纳多出去")
                    bcx.Image = new Bitmap(Application.StartupPath + @"\Images\arrow_up.gif");
            }
        }



------解决方案--------------------
DNB中没有DataGridViewButtonXColumn这样的列类型,是楼主自己新增的?
如果是,那么是你自己实现的问题.

如果你不是