Results 1 to 8 of 8

Thread: MSFLEXGRID Easy question ? ? ?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Question

    How can I allow a user to type into a msflexgrid? i have tree columns that represent day, week, and month value and would like the user to supply in the grid. Any ideas on this matter would be greatly appereciated.
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  2. #2
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553

    Talking

    Code:
    Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)
      MSFlexGrid1.TextMatrix(MSFlexGrid1.RowSel, MSFlexGrid1.ColSel) = MSFlexGrid1.TextMatrix(MSFlexGrid1.RowSel, MSFlexGrid1.ColSel) & Chr$(KeyAscii)
    End Sub

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441
    Mad Compie,

    You are the man. I thought I would have to revert to a DBGrid. Something so hard, yet so simple. Thanks, you saved me a hell of alot of redoing...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Angry

    Mad Compie: or anyone who may reply,

    New question same subject.

    As before, my three input columns will be numeric, but how can i make it so that the user can use the backspace key and delete key for edit purposes. What I've done so far works, except if the user must change the typed in value.

    Please help.
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  5. #5
    New Member
    Join Date
    Aug 2000
    Location
    France
    Posts
    7

    Lightbulb

    I had the same problem as you and I found a solution finally

    You have to use a textbox that you dont make visible in a first time.
    You place the textbox at the same Left and Top of your MSFlexGrid.
    Code:
    TextBox.Visible = False
    TextBox.Top = MSFlexGrid.Top
    TextBox.Left = MSFlexGrid.Left
    When the user click on the cell you want, you have to display the textbox but before place it over the cell :
    Code:
    TextBox.Left = TextBox.Left + MSFlexGrid.CellLeft
    TextBox.Top = TextBox.Top + MSFlexGrid.CellTop
    TextBox.Visible = True
    TextBox.SetFocus
    And you have to play with the KeyPress event of the TextBox.
    If "Enter" (13) is pressed by the user, the textbox return to his initial place, is invisible, and the cell contains the text write in the textbox.
    Code:
    Private Sub TextBox_KeyPress(KeyAscii As Integer)
    
    Select Case KeyAscii
    Case vbKeyReturn
    MSFlexGrid.TextMatrix(MSFlexGrid.Row, MSFlexGrid.Col) = TextBox.Text
    TextBox.Visible = False
    TextBox.Left = MSFlexGrid.Left
    TextBox.Top = MSFlexGrid.Top
    
    Case vbKeyBack
    TextBox.Text = Left(TextBox.Text, Len(TextBox.Text) - 1)
    End Select
    
    End Sub
    You can do a lot a things such as move the textbox to the next cell when the user press the up/down key or left/right key.

    Nicolas Joannidès
    Visual Basic, C, ASP
    [email protected]

  6. #6
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    There is also an API that handles numeric key presses:
    Code:
    'This project needs a TextBox
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Const GWL_STYLE = (-16)
    Const ES_NUMBER = &H2000&
    Public Sub SetNumber(NumberText As TextBox, Flag As Boolean)
        Dim curstyle As Long, newstyle As Long
    
        'retrieve the window style
        curstyle = GetWindowLong(NumberText.hwnd, GWL_STYLE)
    
        If Flag Then
           curstyle = curstyle Or ES_NUMBER
        Else
           curstyle = curstyle And (Not ES_NUMBER)
        End If
    
        'Set the new style
        newstyle = SetWindowLong(NumberText.hwnd, GWL_STYLE, curstyle)
        'refresh
        NumberText.Refresh
    End Sub
    Private Sub Form_Load()
      SetNumber Text1, True
      Me.Caption = "Now, try typing some letters into the textbox"
    End Sub

  7. #7
    Guest
    How can we do to limit only numbers in the grids but not in the textbox, can we do that by using api? because i need to move the textbox from grid to grid... and needs lots of code... hope i can use api to control the entry and use what was mentioned (the best codes) above that can save lots of time
    dragon

  8. #8
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    I don't think there is any API to do this. You should write your own code to convert (to filter) the TextBox Text property to the grid TextMatrix property.

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