I have a datagridview where i add rows using array like this:
Dim srow() As String = {getIDprodus(cmbprodus.Text), cmbprodus.Text, getprodusforma(cmbprodus.Text), txtcantitate.Text}
griddetalii.Rows.Add(srow)
Next, i need to let user to modify the added row. So when user selects a row and press EDIT, a new form is popped out using this code:
Dim i = griddetalii.CurrentRow.Index
frmdetaliiiesire.cmbprodus.Text = griddetalii.Item(0, i).Value
frmdetaliiiesire.txtcantitate.Text = griddetalii.Item(1, i).Value
frmdetaliiiesire.StartPosition = FormStartPosition.CenterScreen
frmdetaliiiesire.ShowDialog()
In that form, the user can change the 2 values and after that, he clicks ok with this code:
frmiesiri.griddetalii.Rows(CInt(TextBox1.Text)).Cells(0).Value = cmbprodus.Text
frmiesiri.griddetalii.Rows(CInt(TextBox1.Text)).Cells(1).Value = txtcantitate.Text
In textbox1 i have put the index of the current row selected in grid
The problem is when i push OK, the applications crashes and i receive an error: INDEX WAS OUT OF RANGE
If the users changes the values from the same form, it's works. But changing them from another form crashes the applications
underneath the datagridview, i put a textbox and next code:
vb Code:
Private Sub griddetalii_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles griddetalii.CellContentClick
TextBox1.Text = e.RowIndex
End Sub
but when i click the first row, the value in the textbox is 3 :|
why ?
i have created a new simple project, and i get no error when i try to update the datagridview from another form... it works perfectly with the same code....
i'll have a look at it later this evening (it's 8.15pm here now). just a guess though, is frmiesiri a child form, + do you have more than 1 instance of frmiesiri open at 1 time?