1

I'm working with DataGridView in C#. I fill it with a table from database using BindingSource. After filling the DataGridView I need to add a row of checkboxes that should be first in the table, to enable data filtering in future.

I mean: for example after clicking "Load" button I get DataGridView filled with 4 columns of data and the first row should consists of checkboxes.

I confused. I use

DataGridViewCheckBoxCell checkCell = new DataGridViewCheckBoxCell();
SourceDGV.Rows.Add(checkCell);

I mean here: enter image description here

But after clicking load button it says You can't add rows to databounded DataGridView

Sorry if ecxeption translated wrong, I translated it from Ukrainian.

Any help appreciated.

3
  • 1
    you can't add a custom row of checkboxes in a databound datagridview. Make it unbound and add all your rows manually or change the logic of your interface Commented Aug 9, 2014 at 16:48
  • @Vland thanx, I know it, but isn't there any way to do it? B/c at first I don't know the number of columns I'll get Commented Aug 9, 2014 at 16:51
  • 1
    a) to add to a databound dgv you need to actually add to the datasource. b) all rows have the same datatype in the same respective columns, so as sriram says this functionaltity won't be available in a DVG alone. Commented Aug 9, 2014 at 16:51

1 Answer 1

1

Am afraid, there is no concept of whole rows to be of some type(checkbox in your case) in DataGridView. It is other way around. You can have whole column to be of checkbox type. You'd use DataGridViewCheckBoxColumn for that.

Showing checkboxes in whole row even makes no sense for me: Assume you have data bounded Person object to the DataGridView. So there will be columns like Name, Age, Address. Now, on what basis you show checkbox in the row? How can a Name be converted to a bool(which is what checkbox needs as a value)?

One workaround I can think of would be, handle custom painting, If First row paint checkboxes over there and manually handle their click events. But am pretty sure it's not gonna be easy.

Sign up to request clarification or add additional context in comments.

2 Comments

I need to have a ROW of checkboxes not the COLUMN. thank
@Daria No such feature exist out of the box. You need to roll your own.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.