Click here to Skip to main content
15,895,370 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i wrote a code in vb.net to select and fetch the values of datagridview in textbox


VB
Private Sub dgvitemsearch_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dgvitemsearch.KeyDown
        If e.KeyCode = Keys.Enter And dgvitemsearch.CurrentCell.RowIndex >= 0 Then
          
            Dim row As DataGridViewRow
            row = Me.dgvitemsearch.Rows(dgvitemsearch.CurrentCell.RowIndex)

            txttaxcur.Text = row.Cells("tax").Value.ToString
            txtunit.Text = row.Cells("unitname").Value.ToString
            txtunitid.Text = row.Cells("unit").Value.ToString
            txticode.Text = row.Cells("icode").Value.ToString
            txtiname.Text = row.Cells("iname").Value.ToString
          

        End If
    End Sub


it is working but some times when i change the sequence of lines
assigning the values the code starts misbehaving and says column name not found why is it so?
Posted
Updated 17-May-15 11:07am
v2
Comments
Sergey Alexandrovich Kryukov 17-May-15 15:02pm    
This is so because you 1) have some bugs, 2) because the whole idea of using hard-coded immediate constants like "tax", "unit", etc., instead of some universal, data-agnostic way, is utterly bad.
—SA
yash00121 17-May-15 15:45pm    
i know there is some bug in the code thats why it is not running when i change the sequence but what is the bug ??
Maciej Los 17-May-15 17:15pm    
I'm afraid, an answer to this question is impossible. The sequence of lines has nothing to the issue. I'd suggest to improve this question or delete it.
Ralf Meier 18-May-15 0:30am    
What do you mean exactly with "change the sequence of lines" ?
Have you tested with one of the DaraGrid-own Events which raises an Event with "DataGridViewCellEventArgs" - for example "CellClick". Here you could get the current row (and cell) in the Event-Arguments ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900