我想在DataGridView Windows表单C#的同一列中使用不同的控件类型

时间:2018-10-12 09:03:00

标签: c# winforms datagridview datagridviewcolumn

DataTable dt = new DataTable();    
dt.Columns.Add("name");    
for (int j = 0; j < 10; j++)    
{    
    dt.Rows.Add("");    
}

this.dataGridView1.DataSource = dt;    
this.dataGridView1.Columns[0].Width = 200; 

DataGridViewComboBoxCell ComboBoxCell = new DataGridViewComboBoxCell();

ComboBoxCell.Items.AddRange(new string[] { "aaa","bbb","ccc" });

this.dataGridView1[0, 0] = ComboBoxCell;   
this.dataGridView1[0, 0].Value = "bbb";     

DataGridViewTextBoxCell TextBoxCell = new DataGridViewTextBoxCell();    
this.dataGridView1[0, 1] = TextBoxCell;    
this.dataGridView1[0, 1].Value = "some text";

DataGridViewCheckBoxCell CheckBoxCell = new DataGridViewCheckBoxCell();    
CheckBoxCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;

this.dataGridView1[0, 2] = CheckBoxCell;    
this.dataGridView1[0, 2].Value = true;

从以下位置获得了代码:how to host different controls in the same column in DataGridView control

显示网格并在其中分配了值,但是当我单击单元格时,预期的控件没有显示。有人能找出问题所在吗?

0 个答案:

没有答案