【问题标题】:Call and add item into Comboboxes that are new in datagridview调用并将项目添加到 datagridview 中的新组合框中
【发布时间】:2019-08-03 13:04:51
【问题描述】:
在我的程序中,我在数据网格视图的前两行中有一些带有可变编号(取决于用户选择)的组合框。现在我想添加项目并在其他类中使用它们,但我无权访问它们,因为我不知道在创建之前如何调用它们?(它们是在运行时创建的)
//这是我创建它们的方式:
for (int j = 0; j < columncount; j++) {
dataGridView1.Rows[i].Cells[j] = new DataGridViewComboBoxCell();
}
【问题讨论】:
标签:
c#
datagridview
combobox
datagridviewcomboboxcell
【解决方案1】:
行代码的demo怎么样
public Form0114()
{
InitializeComponent();
Combox();
}
public void Combox()
{
dataGridView1.ColumnCount = 3;
dataGridView1.Columns[0].Name = "Product ID";
dataGridView1.Columns[1].Name = "Product Name";
dataGridView1.Columns[2].Name = "Product Price";
string[] row = new string[] { "1", "Product 1", "1000" };
dataGridView1.Rows.Add(row);
row = new string[] { "2", "Product 2", "2000" };
dataGridView1.Rows.Add(row);
row = new string[] { "3", "Product 3", "3000" };
dataGridView1.Rows.Add(row);
row = new string[] { "4", "Product 4", "4000" };
dataGridView1.Rows.Add(row);
DataGridViewComboBoxColumn cmb = new DataGridViewComboBoxColumn();
cmb.HeaderText = "Select Data";
cmb.Name = "cmb";
cmb.MaxDropDownItems = 4;
cmb.Items.Add("True");
cmb.Items.Add("False");
dataGridView1.Columns.Add(cmb);
}