CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2001
    Posts
    14

    Allowing user input into MS Flex Grid cells

    How do I allow user input into the MS Flex Grid cells ??

    Help appreciated.


  2. #2
    Join Date
    Mar 2000
    Posts
    292

    Re: Allowing user input into MS Flex Grid cells

    Hi.

    I have read in a book that during design-time, you can place a textbox anywhere on your form. Make this textbox invisible. Then at run-time, you can show this textbox and position it above the cell that you clicked for input. The effect is it will be like you are inputting in the grid's cell. After input, you put the contents of the textbox in the cell and hide the textbox again. The events of the flexgrid that you can use are the EnterCell and LeaveCell events.


  3. #3
    Join Date
    Jun 2000
    Posts
    104

    Re: Allowing user input into MS Flex Grid cells

    MSflexgrid does not allow direct userinput .butyou can use a text box to do it.i did this long ago.i will give you the steps.

    take a text box. set it's visible property to false and borderstyle property to none.in the Form_load event set the width and height property of the textbox equal to the cellwidth and cell height property of the grid control.now on the entercell event set the left and top properties of the text box equal to the cellleft and celltop properties of the grid control.make the textbox visible.now on the leavecell event set the text propery of the grid control equal to the text property of the text box.make the textbox invisible.you can add more code to make it look better.let me know if it helps you


  4. #4
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Allowing user input into MS Flex Grid cells

    The MSFlexGrid doesn't inherently allow you to edit data in a cell. Here is the code that illustrates a workaround, using a textbox.

    Place a textbox on a form and set the following properties

    Appearance = 0 'Flat
    BorderStyle = 0 'None
    Height = 375
    Left = 1560
    TabIndex = 1
    Text
    Top = 240
    Width = 1455

    And a MSFlexGrid control with the following properties

    Height = 2895
    Left = 600
    TabIndex = 0
    Top = 720
    Width = 4215
    Rows = 5
    Cols = 5

    Now paste the following code into the form


    private Sub MSFlexGrid1_DblClick()
    GridEdit Asc(" ")
    End Sub

    private Sub MSFlexGrid1_KeyPress(KeyAscii as Integer)
    GridEdit KeyAscii
    End Sub
    Sub GridEdit(KeyAscii as Integer)
    'use correct font
    Text1.FontName = MSFlexGrid1.FontName
    Text1.FontSize = MSFlexGrid1.FontSize
    Select Case KeyAscii
    Case 0 to Asc(" ")
    Text1 = MSFlexGrid1
    Text1.SelStart = 1000
    Case else
    Text1 = Chr(KeyAscii)
    Text1.SelStart = 1
    End Select

    'position the edit box
    Text1.Left = MSFlexGrid1.CellLeft + MSFlexGrid1.Left
    Text1.Top = MSFlexGrid1.CellTop + MSFlexGrid1.Top
    Text1.Width = MSFlexGrid1.CellWidth
    Text1.Height = MSFlexGrid1.CellHeight
    Text1.Visible = true
    Text1.SetFocus
    End Sub

    private Sub MSFlexGrid1_LeaveCell()
    If Text1.Visible then
    MSFlexGrid1 = Text1
    Text1.Visible = false
    End If
    End Sub

    private Sub MSFlexGrid1_GotFocus()
    If Text1.Visible then
    MSFlexGrid1 = Text1
    Text1.Visible = false
    End If
    End Sub

    private Sub Text1_KeyDown(KeyCode as Integer, Shift as Integer)
    Select Case KeyCode
    Case vbKeyEscape
    Text1.Visible = false
    MSFlexGrid1.SetFocus
    Case vbKeyReturn
    MSFlexGrid1.SetFocus
    Case vbKeyDown
    MSFlexGrid1.SetFocus
    DoEvents
    If MSFlexGrid1.Row < MSFlexGrid1.Rows - 1 then
    MSFlexGrid1.Row = MSFlexGrid1.Row + 1
    End If
    Case vbKeyUp
    MSFlexGrid1.SetFocus
    DoEvents
    If MSFlexGrid1.Row > MSFlexGrid1.FixedRows then
    MSFlexGrid1.Row = MSFlexGrid1.Row - 1
    End If
    End Select
    End Sub

    private Sub Text1_KeyPress(KeyAscii as Integer)
    If KeyAscii = vbKeyReturn then KeyAscii = 0
    End Sub





  5. #5
    Join Date
    May 2001
    Posts
    3

    Re: Allowing user input into MS Flex Grid cells

    Input to MSFlexGrid
    ===================
    It is possible to input on flexigrid. Try double click your MSFlexgird, you will find event Grid_KeyPress and Grid_KeyDown:

    Grid_KeyDown(KeyCode As Integer, Shift As Integer)
    Grid_KeyPress(KeyAscii As Integer)

    You can manipulate KeyCode, KeyAscii, and Shift to accpet/control your input. Please refer to ASCII character representation from VB help to know the detail.

    How to accept input?
    The keycode/keyascii represent the character input from keyboard, convert it into character using function chr(KeyAscii) or chr(KeyCode).

    Mail to me if you want the code example:
    [email protected]

    Good luck



  6. #6
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Allowing user input into MS Flex Grid cells

    Where did you get your MSFlexGrid from? The one I got when I installed VB 6.0 PRO does not have those events you described. Could the be from a Addon product?

    John G

  7. #7
    Join Date
    May 2001
    Posts
    36

    Re: Allowing user input into MS Flex Grid cells

    You can go to http://www.share2.com/easygrid/ to download a substitute OCX.
    It's powerful and meets any requirements.



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

Featured