Tech
Forums
Jobs
Books
Events
Videos
Conference
Annual Conference
Bcrypt
Ai Conference
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Post
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
4
Reply
Adding checkbox column in datagridview at specific position.
Ankush
8 years ago
396
Reply
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;
//dt is DataTable
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
Post
Reset
Cancel
Answers (
4
)
Next Recommended Forum
sessions
Asp.net webapp become mobile enabled.