I am developing a windows application using c#.
I have a datagridview in which the data is coming from database based on the value selected in combobox on form, now I want to add checkbox column at first position ( Checkbox column should be first column )
- dgvDetails.DataSource = dt;
- DataGridViewCheckBoxColumn chk = new DataGridViewCheckBoxColumn();
- chk.HeaderText = "";
- chk.Width = 30;
- chk.Name = "chk";
- dgvDetails.Columns.Insert(0, chk);
- dgvDetails.Columns[1].DataPropertyName = "Trans_ID";
- dgvDetails.Columns[1].HeaderText = "Trans ID";
- dgvDetails.Columns[2].DataPropertyName = "UserName";
- dgvDetails.Columns[2].HeaderText = "User Name";
I wrote the following code :-
The number of rows depend upon the value selected in combobox.
This doesn't work properly. When the form is loaded and the value in combobox is selected the checkbox column appears as first column and the data also appears correctly, but when the combobox selected value is changed, the data in datagirdview is jumbled and error occurs