am stuck. I connected a DataGridView to VB so that any information entered from it, should be automatically saved in the Access Database. I want to transfer data from the DatagridView to Microsoft Access tables but unfortunately error keeps stating "Rows cannot be programmatically added to the DataGridView rows collection when the control is data-bound". Is there anyway to assist me please? Thank you!
Here's the code.
If TextBox3.Text = "" And TextBox4.Text = "" Then
MsgBox("Enter Data")
Else
Dim Quantity As String = ListBox3.Text
End If
ListBox1.Items.Add(TextBox3.Text.Trim())
ListBox5.Items.Add(TextBox4.Text.Trim())
ListBox3.Items.Add(TextBox5.Text.Trim())
DataGridView1.Rows.Add("", ListBox1.Text, "", "", ListBox5.Text, ListBox3.Text)
If you bind data to the grid then you need to add a new row to the DataTable .
Here is short example:
Dim newRow As DataRow
newRow = dataSet.Tables(0).NewRow
newRow.Item(0) = txtValue1.Text
newRow.Item(1) = txtValue2.Text
dataSet.Tables(0).Rows.Add(newRow)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.