在我的程序中,我在datagrid视图的前两行中有一些带有可变编号(取决于用户选择)的组合框。现在我想添加项目并在其他类中与它们一起使用,但是由于我不知道如何在创建之前调用它们(我是在运行时创建的)而无法访问它们
//这是我创建它们的方式:
for (int j = 0; j < columncount; j++) {
dataGridView1.Rows[i].Cells[j] = new DataGridViewComboBoxCell();
}
答案 0 :(得分:0)
关于线路代码的演示
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);
}