在我的程序中,我有一些combobox在datagrid视图的前两行中具有可变数字(取决于用户选择(。现在,我想添加项目并在其他类中与它们合作,但我无法访问它们,因为我不知道如何在创建之前打电话?(它们是在运行时创建的(
//这就是我创建它们的方式:
for (int j = 0; j < columncount; j++) {
dataGridView1.Rows[i].Cells[j] = new DataGridViewComboBoxCell();
}
line代码的演示
怎么样 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);
}