[2008] Adding row to unbound DataGridView
I am trying to display unbound data in a DataGridView. I set up columns already design-time. I am at a loss for creating code that adds a new row using the column schema that was created in the Designer?
Something like this?
vb Code:
dim newrow as DataGridViewRow
newrow.cells.item("name").value = "text here"
datagridview1.rows.add(newrow)
I get an error saying the 'name' column was not found?
Re: [2008] Adding row to unbound DataGridView
You should call datagridview1.Rows.Add() to generate the row. That way it will have the correct number of columns and each will be of the appropriate type. If you just create a DataGridViewRow yourself then how would it know what columns the grid has?
Add will return the index of the row, so you can then access it from the Rows collection by that index to set its fields.