大家好,就是我在winform 窗体中放置了一个名叫DataGridView1 的控件,我想把:
1. 第一列设置为 CheckBox样式,第2列设置为ComboBox 样式的,该怎么用C#程序实现呢?
2. 怎么初始化和 读取CheckBox和ComboBox列?
谢谢大家的帮忙!
在窗体上添加一个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();