VB.net Adding a row to a DataGridView that has a checkbox column

Murray Brown
Murray Brown used Ask the Experts™
on
Hi

  What VB.net code do I use to add a row of data to a DataGridView where the last column is a checkbox column.
 I have tried the following to approaches which both don't work

  DataGridView1.Rows.Add(New String() {oColumnName, "", ""})
DataGridView1.Rows.Add(New String() {oColumnName, "", False})
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
DataGridView1.Rows.Add(oColumnName, "", False)
Most Valuable Expert 2012
Top Expert 2014
Commented:
You can also do this:

Dim dtrn As Datarow
dtrn = YourDataGridView.NewRow
dtrn("Col1") = "Some Value"
dtrn("Col2") = True

YourDataGridView.Rows.Add(dtrn)

This method is useful if you need to apply logic to the value of a Column.
Murray BrownASP.net/VSTO Developer

Author

Commented:
Thanks
Glad I could help. One more comment though: databound controls are UI representation of data. In most cases they are intended to view data and to edit data inside them (using keyboard/mouse). If you want change smth in code without user action it's better to change data rather then control properties. I.e. if your datagridview bounded to datatable (either via bindingsource or directly) - it's better to add row to datatable and gridview will display changes.
Murray BrownASP.net/VSTO Developer

Author

Commented:
Thanks for the advice

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial