how to add row in datagridview in vb.net code example
Example 1: vb.net add row to datagridview programmatically
Private Sub SurroundingSub()
Dim rowId As Integer = dataGridView1.Rows.Add()
Dim row As DataGridViewRow = dataGridView1.Rows(rowId)
row.Cells("Column1").Value = "Value1"
row.Cells("Column2").Value = "Value2"
End Sub
Example 2: dynamically add rows to datagridview c#
DataTable dt = new DataTable();
for (int i = 0; i < count; i++)
{
dt.Columns.Add(fromFileFields[i]);
}
for (int i = 0; i < count; i++)
{
var row = dt.NewRow();
dt.Rows.Add(row);
}
datagridview.DataSource = dt;