Hi,
Lets say we already have DataGridView control as 'dgView' defined on our form with our columns defined as FirstName, LastName and Address.
All columns were added from Design view of the form.
Now in code behind, if we just to add row without binding it to some datasource, it would be:
Happy Coding!
Lets say we already have DataGridView control as 'dgView' defined on our form with our columns defined as FirstName, LastName and Address.
All columns were added from Design view of the form.
Now in code behind, if we just to add row without binding it to some datasource, it would be:
dgView.Rows.Add(New String() {"John","Doe","123 Main St, City UK"})
If we want to bind it with dataset or datatable then it would be :
Dim dt As New
DataTable
dt.Columns.Add("FirstName")
dt.Columns.Add("LastName")
dt.Rows.Add(New
String() {"saqib",
"mahmood"})
' This property is set if we dont
have predefined columns in DataGridView.
dgView.AutoGenerateColumns = True
dgView.DataSource = dt
dt.Columns.Add("FirstName")
dgView.AutoGenerateColumns = True
Happy Coding!
No comments:
Post a Comment