Results 1 to 19 of 19

Thread: VB 2008 - problem updating datagridview

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2009
    Posts
    15

    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?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: VB 2008 - problem updating datagridview

    put a msgbox in there + check that cint(textbox1.text) is what you expect it to be

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2009
    Posts
    15

    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

  4. #4

    Thread Starter
    New Member
    Join Date
    Dec 2009
    Posts
    15

    Re: VB 2008 - problem updating datagridview

    i have made some things ...

    underneath the datagridview, i put a textbox and next code:
    vb Code:
    1. Private Sub griddetalii_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles griddetalii.CellContentClick
    2.                 TextBox1.Text = e.RowIndex
    3.     End Sub

    but when i click the first row, the value in the textbox is 3 :|
    why ?

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    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

  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 2009
    Posts
    15

    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
    Attached Files Attached Files

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    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?

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    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

  9. #9

    Thread Starter
    New Member
    Join Date
    Dec 2009
    Posts
    15

    Re: VB 2008 - problem updating datagridview

    i'm an idiot

  10. #10
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: VB 2008 - problem updating datagridview

    it worked then?

  11. #11

    Thread Starter
    New Member
    Join Date
    Dec 2009
    Posts
    15

    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
    Last edited by Lullly; Feb 21st, 2010 at 04:21 PM.

  12. #12
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: VB 2008 - problem updating datagridview

    ok try this (in frmdetaliiiesire):

    vb Code:
    1. Private Sub btnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click
    2.     Me.Owner.griddetalii.Item(1, CInt(lblid.Text)).Value = cmbprodus.Text
    3.         Me.Owner.griddetalii.Item(3, CInt(lblid.Text)).Value = txtpretunitate.Text
    4.         Me.Owner.griddetalii.Item(4, CInt(lblid.Text)).Value = txtcantitate.Text
    5.         Me.Owner.griddetalii.Item(5, CInt(lblid.Text)).Value = txttva.Text
    6.     Me.Close()
    7. End Sub

  13. #13

    Thread Starter
    New Member
    Join Date
    Dec 2009
    Posts
    15

    Re: VB 2008 - problem updating datagridview

    it says: griddetalii is not a member of System.Forms.form

  14. #14
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: VB 2008 - problem updating datagridview

    vb Code:
    1. Private Sub btnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click
    2.     directcast(Me.Owner, frmiesiri).griddetalii.Item(1, CInt(lblid.Text)).Value = cmbprodus.Text
    3.     directcast(Me.Owner, frmiesiri).griddetalii.Item(3, CInt(lblid.Text)).Value = txtpretunitate.Text
    4.     directcast(Me.Owner, frmiesiri).griddetalii.Item(4, CInt(lblid.Text)).Value = txtcantitate.Text
    5.     directcast(Me.Owner, frmiesiri).griddetalii.Item(5, CInt(lblid.Text)).Value = txttva.Text
    6.     Me.Close()
    7. End Sub

  15. #15

    Thread Starter
    New Member
    Join Date
    Dec 2009
    Posts
    15

    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
    Last edited by Lullly; Feb 21st, 2010 at 04:39 PM.

  16. #16
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: VB 2008 - problem updating datagridview

    still alive i hope?

    try this now:
    Attached Files Attached Files

  17. #17

    Thread Starter
    New Member
    Join Date
    Dec 2009
    Posts
    15

    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

  18. #18
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: VB 2008 - problem updating datagridview

    Quote Originally Posted by Lullly View Post
    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

  19. #19

    Thread Starter
    New Member
    Join Date
    Dec 2009
    Posts
    15

    Re: VB 2008 - problem updating datagridview

    thanks again man, many thanks

    i will try tomorow and understand your modifications


    thanks man I SIMPLY LOVE YOU

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width