Datagrid view problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • charvi
    New Member
    • May 2007
    • 121

    Datagrid view problem

    Please help.
    If I want to navigate datagrid rows through keyboard (Key down key). When I write code in keydown event it gives previous record.
    Thanks in advance.
  • QVeen72
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    Hi,

    As I understand, u want to write Code when the Down Arrow Is Pressed, Move Previous...?
    If yes, Then First Make Form's KeyPreview =True, and write code in KeyDown or Key Up Event :

    Code:
    If KeyCode=38 Then
        'Up Arrow Pressed, Write code to Show Next Rec
    ElseIf KeyCode = 40 Then
        'Down Arrow Presses, Prev Rec
    End If
    Regards
    Veena

    Comment

    • charvi
      New Member
      • May 2007
      • 121

      #3
      hi
      it did not solve
      i have written the code
      but when a down key is pressed it gives the previous record in the text box
      pls help
      thanks

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Originally posted by charvi
        ... it gives the previous record in the text box
        Please show us the actual code that you used.

        Comment

        • charvi
          New Member
          • May 2007
          • 121

          #5
          The code I used to navigate through key down key is
          I have written the code in datagrid1 keydown event
          i.e
          [CODE=vb]dgbus.MarqueeSt yle=dbgHighligh tRow
          Dim rsd As New ADODB.Recordset
          rsd.Open "select * from business where slno=" & dgbus.Columns(0 ) & "", conn, adOpenDynamic, adLockOptimisti c

          If rsd.EOF = False Then
          With rsd

          cmdsave.Enabled = False

          txtSlno.Text = dgbus.Columns(0 )
          txtName.Text = dgbus.Columns(1 )
          If .Fields(2) <> "" Then
          txtDes.Text = dgbus.Columns(2 )
          endif[/CODE]

          But it gives me the previous record of selected record.
          Thanks.
          Last edited by Killer42; Aug 27 '07, 07:21 AM. Reason: Added CODE=vb tag

          Comment

          • QVeen72
            Recognized Expert Top Contributor
            • Oct 2006
            • 1445

            #6
            Hi,

            In your code, where you are checking the KeyCode = 50...? as I said in my prev post...
            And write the Code in KeyUp event,

            Regards
            Veena

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              If I'm following this correctly, I believe you have a timing issue. The KeyDown event fires as soon as you press the key. But you want to wait until after the datagrid moves to the next record, then retrieve the details.

              Perhaps you need to place your code somewhere else. Doesn't the datagrid control have events that fire after moving to a new record? Let's see... just browsing the documentation, perhaps the RowColChange, Scroll or SelChange events would fit the bill.

              By the way, isn't navigation via the keyboard already built into the datagrid control? It looks to me as though what you are trying to do is not navigation of the datagrid, but pulling information out of it, after the navigation takes place. Does that sound right?

              Oh, and by the way. If you are going to post code here, it's generally better to copy and paste it directly from the IDE rather than typing it in here. That way we get more reliable information, and you get more reliable answers.

              Comment

              • charvi
                New Member
                • May 2007
                • 121

                #8
                Originally posted by Killer42
                ... Perhaps you need to place your code somewhere else. Doesn't the datagrid control have events that fire after moving to a new record? Let's see... just browsing the documentation, perhaps the RowColChange, Scroll or SelChange events ...
                But I tried in Scroll event also but it dos not work. It will Scroll but I want to put the record highlighted to text box where it puts the previous record.
                Last edited by Killer42; Aug 28 '07, 03:31 AM. Reason: Reduced excessive quote block

                Comment

                • QVeen72
                  Recognized Expert Top Contributor
                  • Oct 2006
                  • 1445

                  #9
                  Hi,

                  Write the code in "RowColChan ge" event...

                  REgards
                  Veena

                  Comment

                  Working...