I am using vb.net 2010. I have a datagridview whose data source is a data table. I dynamically add rows to the data table.
Friend WithEvents DGVCusClient As System.Windows.Forms.DataGridView
DGVCusClient.DataSource = m_table
Private Sub DVGCusClient_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DGVCusClient.DoubleClick
Dim newRow As DataRow = m_table.NewRow()
newRow.Item(colNameCustomer) = "Customer Name"
newRow.Item(colNameClient) = "Client Name"
m_table.Rows.Add(newRow)
End Sub
After adding the new row, m_table is correct. However, DVGCusClient not only adds this row, but also adds two additional blank rows at the bottom. I have no idea where these two blank rows come from.
Why I use above code is as follows:
Use a data grid view to display data. When a user clicks a row, another form is opened which allows user to search/input some data.When the user closes the form, all data is saved to a data table and shown on the data grid view.
I think its adding additional row because of this line: m_table.Rows.Add(newRow)
Because newRow.item will add new row to the table