Results 1 to 2 of 2

Thread: Re: How to trap messages in msflexgrid?

  1. #1
    Guest

    Question

    Hi! My program cannot detect when user press the navigation keys (for e.g. left arrow, right arrow, etc.) under KeyPress or KeyUp or KeyDown events of msflexgrid.

    So I believe I need to used some Win API in order to detect all the navigation keys which I totally does not know how to do it.

    Can anyone help me in this?

    Thank you in advanced!

  2. #2
    Lively Member
    Join Date
    Jan 2000
    Location
    Neenah, WI USA
    Posts
    95
    Try using this code. It works for me for backspace, left arrow, right arrow, up arrow, down arrow, enter moves to right. It wraps to next row at end of row...

    To test, create new form, drop MSHFlexgrid control onto it, and paste this code in...

    *********************************
    ' set up a 5 x 5 grid...

    Private Sub Form_Load()
    MSHFlexGrid1.Cols = 5
    MSHFlexGrid1.Rows = 5

    End Sub

    Private Sub MSHFlexGrid1_KeyPress(KeyAscii As Integer)

    'check for carriage return - move to next cell...

    If Chr(KeyAscii) = Chr(13) Then
    If MSHFlexGrid1.Col >= MSHFlexGrid1.Cols - 1 Then
    MSHFlexGrid1.Col = 1
    If MSHFlexGrid1.Row >= MSHFlexGrid1.Rows - 1 Then
    MSHFlexGrid1.Row = 1
    Exit Sub
    Else
    MSHFlexGrid1.Row = MSHFlexGrid1.Row + 1
    Exit Sub

    End If

    Else
    MSHFlexGrid1.Col = MSHFlexGrid1.Col + 1
    Exit Sub
    End If
    End If


    ' handle backspace
    If Chr(KeyAscii) = Chr(8) Then
    MSHFlexGrid1.Text = Mid(MSHFlexGrid1.Text, 1, Len(MSHFlexGrid1.Text) - 1)
    Exit Sub
    End If

    'other key pressed... append to existing text

    MSHFlexGrid1.Text = MSHFlexGrid1.Text & Chr(KeyAscii)

    End Sub
    ******************************

    As I said, this should work.


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