Rows cannot be programmatically added to the DataGridView rows collection when the control is data-bound.

  • Thread starter Thread starter Omi4u
  • Start date Start date
O

Omi4u

Guest
i am getting this error while entering data from textbox to datagrid.


i have a method



Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown



Dim dt As New DataTable
dt.Columns.Add(New DataColumn() With {.ColumnName = "hiddenid", .DataType = GetType(Integer),
.AutoIncrement = True, .AutoIncrementSeed = 1})

dt.Columns("hiddenid").ColumnMapping = MappingType.Hidden



dt.Columns.Add(New DataColumn() With {.ColumnName = "autonumber", .DataType = GetType(String)})
dt.Columns.Add(New DataColumn() With {.ColumnName = "location", .DataType = GetType(String)})
dt.Columns.Add(New DataColumn() With {.ColumnName = "date", .DataType = GetType(String)})





bsData.DataSource = dt
NDRDataGridView.DataSource = bsData
' Label3.DataBindings.Add("text", bsData, "stockin_id")








End Sub


Private Sub AutonumberTextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles AutonumberTextBox1.KeyPress
If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then

If Not String.IsNullOrWhiteSpace(AutonumberTextBox.Text) Then
CType(bsData.DataSource, DataTable).Rows.Add(New Object() {Nothing, AutonumberTextBox1.Text, LocationTextBox.Text, DateTextBox1.Text})
bsData.MoveLast()
End If

End If

End Sub



but when i use above codes, it worked for me but it do not allow me to see relationship data.


i need

i have two tables table1 = t1
table 2 =T1r


both have relationship

i want when user fill textbox and press enter in last textbox, the data of all other textboxes get added in datagrid with autonumber (identity from sql)


please help and guide me with codes

Continue reading...
 
Back
Top