1

In my program I have some combobox with variable number(depends on user choice) in first two rows of a datagrid view. Now I want to add item and work with them in other classes but I don't have access to them because I don't know how to call them before creating?(they are been created during runtime)

//this is how I create them:

for (int j = 0; j < columncount; j++) {
    dataGridView1.Rows[i].Cells[j] = new DataGridViewComboBoxCell();
}
Prochu1991
  • 443
  • 5
  • 20
Ali Madani
  • 11
  • 2

1 Answers1

0

what about the demo of line code

  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);
        }
Prochu1991
  • 443
  • 5
  • 20