I am trying to have 2 check boxes in rows from first 2 columns and rest with some text. With my code I have the text boxes at each row but at the last 2 columns.
I want to be able to put my check boxes before the text entries.
I tried changing order of the code but I cannot get the result I desire.
What could be wrong with my code here?
dataGridView1.ColumnCount = 4;
dataGridView1.Columns[0].Name = "Delete";
dataGridView1.Columns[1].Name = "Edit";
dataGridView1.Columns[2].Name = "User Name";
dataGridView1.Columns[3].Name = "Password";
DataGridViewCheckBoxColumn delete = new DataGridViewCheckBoxColumn();
DataGridViewCheckBoxColumn edit = new DataGridViewCheckBoxColumn();
dataGridView1.Columns.Add(delete);
delete.HeaderText = "Delete";
dataGridView1.Columns.Add(edit);
edit.HeaderText = "Edit";
string[] row;
row = new string[] { "1", "Product 1", "1000", "1" };
dataGridView1.Rows.Add(row);
row = new string[] { "2", "Product 4", "2000", "2" };
dataGridView1.Rows.Add(row);
row = new string[] { "3", "Product 5", "3000", "3" };
dataGridView1.Rows.Add(row);
row = new string[] { "4", "Product 6", "4000", "4" };
dataGridView1.Rows.Add(row);
The DataGridView.Rows.Add() function takes an array of objects. The object type you provide should depend on the type of each column.
Therefore, if you set up your columns properly, you should be able to write:
In your original code you added the columns twice in two different ways. Pick one method of adding the columns.