首页 新闻 会员 周边

c# DataGridView1 列样式设置为 DataGridViewComboBoxColumn、DataGridViewCheckBoxColumn

0
悬赏园豆:5 [已解决问题] 解决于 2014-04-15 16:37

大家好,就是我在winform 窗体中放置了一个名叫DataGridView1 的控件,我想把:

1. 第一列设置为 CheckBox样式,第2列设置为ComboBox 样式的,该怎么用C#程序实现呢?

2. 怎么初始化和 读取CheckBox和ComboBox列?

谢谢大家的帮忙!

< >
分享
最佳答案
0

在窗体上添加一个DataGridView1,往里面添加两个列,然后打开Form1.Designer.cs文件,在里面会找到下面几行代码

private System.Windows.Forms.DataGridViewCheckBoxColumn CCheck;
 private System.Windows.Forms.DataGridViewComboBoxColumn CComBox;

InitializeComponent()方法

this.CCheck = new System.Windows.Forms.DataGridViewCheckBoxColumn();
 this.CComBox = new System.Windows.Forms.DataGridViewComboBoxColumn();

this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.CCheck,
            this.CComBox});

 //
            // CCheck
            //
            this.CCheck.HeaderText = "选择列";
            this.CCheck.Name = "CCheck";
            //
            // CComBox
            //
            this.CComBox.HeaderText = "列表列";

this.CComBox.Items.AddRange(new object[] {
            "1",
            "2",
            "3"});
            this.CComBox.Name = "CComBox";

this.dataGridView1.Rows.Add(true, "1");//添加一行数据

DataGridViewRow dgvr=  this.dataGridView1.Rows[0];//读取一行数据
            bool checkbox=(bool) dgvr.Cells["CCheck"].Value;
         string combobox =(string) dgvr.Cells["CComBox"].Value.ToString();

 

 

 

收获园豆:5
贪心狸猫 | 小虾三级 |园豆:872 | 2014-03-25 16:48
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册