初次接触该控件,不知怎样实现如下功能:
第一列为序号,从1开始自动增加1
第二列为设定颜色,类型为按钮,点击时弹出颜色对话框,选定的颜色即成为按钮颜色
第三列为numericUpDown,可以设定数值和范围另外的问题是这样的结构还能用数据绑定么?数据持久化用什么方案比较好,或者有更好的控件实现这些功能不胜感谢

解决方案 »

  1.   

    第一列获取行号+1
    第二列设置columnType为DataGridViewTextBoxColumn。
    第三列设置columnType为DataGridViewComboBoxColumn。
      

  2.   

    如果初次接触微软的DataGridView,这样的功能确实不太容易做,虽然都能做到。
    用DevExpress的Grid控件就容易好多。如果要用DataGridView来练手也是个好主意,这时你可参考IDataGridViewEditingControl接口,以及MSDN关于该接口的例子。
    对于带颜色的按钮列,可能要像DataGridViewButtonColumn那样自己画按钮。
    对于numericUpDown,仿照上述的接口例子就可以了。
      

  3.   

    我不是想练手,winform要是有类似web下的table控件就好了,这样可以任意控制每行的内容按钮颜色怎么绑定?
      

  4.   

    回答第一问 vs2008通过
    第一列为序号,从1开始自动增加1 首先在窗体的构造函数里写:
    InitializeComponent();
    this.dataGridView1.RowPostPaint += new DataGridViewRowPostPaintEventHandler(DrawRowIndex);
    然后写一个事件处理:
    private void DrawRowIndex(object sender, DataGridViewRowPostPaintEventArgs e)//给行加上序列.
            {
                Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
                   e.RowBounds.Location.Y,
                   this.dataGridView1.RowHeadersWidth - 4,
                   e.RowBounds.Height);            TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
                    this.dataGridView1.RowHeadersDefaultCellStyle.Font,
                    rectangle,
                    this.dataGridView1.RowHeadersDefaultCellStyle.ForeColor,
                    TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
            }