VB 2008 - problem updating datagridview
Hello everyone,
I'm stuck on a stupid problem
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
Can someone help me?
Re: VB 2008 - problem updating datagridview
put a msgbox in there + check that cint(textbox1.text) is what you expect it to be
Re: VB 2008 - problem updating datagridview
i did....
it says that index = 0 and that's corect, it's the first row from the grid. but i still receive the "INDEX OUT OF RANGE" error :(
Re: VB 2008 - problem updating datagridview
i have made some things ...
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 ?
Re: VB 2008 - problem updating datagridview
i don't know why that'd happen.
maybe if you post more of your code or zip your project + post it, i might find it
1 Attachment(s)
Re: VB 2008 - problem updating datagridview
here you go...maybe you can explain 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....
ty man
Re: VB 2008 - problem updating datagridview
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?
Re: VB 2008 - problem updating datagridview
it might be that you load frmiesiri as form3 in your mdiparent form, so that is what you should refer to it as:
form3.griddetalii.Rows(CInt(TextBox1.Text)).Cells(0).Value = cmbprodus.Text
form3.griddetalii.Rows(CInt(TextBox1.Text)).Cells(1).Value = txtcantitate.Text
Re: VB 2008 - problem updating datagridview
Re: VB 2008 - problem updating datagridview
Re: VB 2008 - problem updating datagridview
no, it didnt
when i write form3, it says that: form3 is not defined.
:(
LE: only one instance of frmiesiri is open at a time :)
Re: VB 2008 - problem updating datagridview
ok try this (in frmdetaliiiesire):
vb Code:
Private Sub btnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click
Me.Owner.griddetalii.Item(1, CInt(lblid.Text)).Value = cmbprodus.Text
Me.Owner.griddetalii.Item(3, CInt(lblid.Text)).Value = txtpretunitate.Text
Me.Owner.griddetalii.Item(4, CInt(lblid.Text)).Value = txtcantitate.Text
Me.Owner.griddetalii.Item(5, CInt(lblid.Text)).Value = txttva.Text
Me.Close()
End Sub
Re: VB 2008 - problem updating datagridview
it says: griddetalii is not a member of System.Forms.form
Re: VB 2008 - problem updating datagridview
vb Code:
Private Sub btnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click
directcast(Me.Owner, frmiesiri).griddetalii.Item(1, CInt(lblid.Text)).Value = cmbprodus.Text
directcast(Me.Owner, frmiesiri).griddetalii.Item(3, CInt(lblid.Text)).Value = txtpretunitate.Text
directcast(Me.Owner, frmiesiri).griddetalii.Item(4, CInt(lblid.Text)).Value = txtcantitate.Text
directcast(Me.Owner, frmiesiri).griddetalii.Item(5, CInt(lblid.Text)).Value = txttva.Text
Me.Close()
End Sub
Re: VB 2008 - problem updating datagridview
Object reference not set to an instance of an object.
:( :( :( i think i will soon hang myself
LE: i realize now, the problem is because i use MDiform :)
the test application i have used so far, i have added a mdiform, and i still get the index out of range error. damn mdiform
1 Attachment(s)
Re: VB 2008 - problem updating datagridview
still alive i hope?
try this now:
Re: VB 2008 - problem updating datagridview
OMG OMG OMG OMG OMG OMG OMG OMG
it works........
unfortunatelly, it's verry late for me and i have to go to bed to sleep few hours before i go to work.
man, i must admit, you're a genius. How can i rate you?
thanks alot, i hope somedays i will manage to help you too :)
thanks again
Re: VB 2008 - problem updating datagridview
Quote:
Originally Posted by
Lullly
LE: i realize now, the problem is because i use MDiform :)
the test application i have used so far, i have added a mdiform, and i still get the index out of range error. damn mdiform
it is because of the mdiform + the child form, but it's not a problem
Re: VB 2008 - problem updating datagridview
thanks again man, many thanks
i will try tomorow and understand your modifications
thanks man :D I SIMPLY LOVE YOU