0

As you can see in this tutorial there are several ways to fill a DataGridView that contains a CheckBox Column with data. They are:

  • Binding a List to a DataGridView having a bool property
  • Binding a datatable to a DataGridView having a bool column
  • Adding a checkbox column (DataGridViewCheckBoxColumn) to the DataGridView.

Ignoring the third one, there is a difference between the first two (and you can see it in the result screen in the tutorial).

When you use a List, you get what you want: A DataGridView with a column that has CheckBox columns

However if you use the second method (a datatable), you get a DataGridView with a column that has CheckBox columns but with an extra empty row!

You can see it in the Pic in the tutorial: The extra row

Not only that but if you check on the empty row checkbox you get another empty row and that could go forever.

This is obviously undesirable behavior. So far I have been using Lists and they work ok but I would like to use dataTables to fill the DataGridView. Is there a way to avoid having this undersirable behavior and just get the exact rows?

KansaiRobot
  • 7,564
  • 11
  • 71
  • 150
  • 1
    This is a DGV property AllowUserToAddRows. simply turn it off! - And no, I doubt it has anything to do with what else you did, including adding that bool column. – TaW Sep 12 '18 at 09:33
  • @TaW so simple! Thanks! The curious thing is that with Lists this does not happen! – KansaiRobot Sep 12 '18 at 09:35
  • Indeed! Loks like the reason is that DataTable is able to accept new rows but List isn't. [See here](https://stackoverflow.com/questions/11799661/datagridview-allowusertoaddrow-property-doesnt-work) – TaW Sep 12 '18 at 10:30

0 Answers0