Results 1 to 3 of 3

Thread: Can I write in a FlexGrid?

  1. #1

    Thread Starter
    Junior Member Jethro Tull's Avatar
    Join Date
    May 2005
    Location
    Buenos Aires - Argentina
    Posts
    31

    Can I write in a FlexGrid?

    The question is: can I use a FlexGrid (or any of the similar objects) as an Excel spreadsheet to wite data in the cells?

    I only can use it to fill the cells by programming routines, not as a keyboard entry.
    Last edited by Jethro Tull; May 11th, 2005 at 11:06 AM.

  2. #2
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Can I write in a FlexGrid?

    There is no direct way to do this but, have a look at the following, it may help

    VB Code:
    1. Option Explicit
    2.  
    3. ' to store the row/column of the cell
    4. ' being edited
    5. Dim m_lCellCol As Long
    6. Dim m_lCellRow As Long
    7.  
    8. Private Sub Form_Load()
    9.   m_lCellRow = -1
    10.   m_lCellCol = -1
    11.   txtCell.BorderStyle = 0
    12.   txtCell.Visible = False
    13.   ' set the text background color to the
    14.   ' backcolor of the tooltip text to make
    15.   ' the cell being edited having a different color
    16.   txtCell.BackColor = vbInfoBackground
    17.   MSFlexGrid1.Cols = 10
    18.   MSFlexGrid1.Rows = 10
    19. End Sub
    20.  
    21. Private Sub MSFlexGrid1_DblClick()
    22.   showTxtCell
    23. End Sub
    24.  
    25. Private Sub MSFlexGrid1_RowColChange()
    26.   removeTxtCell
    27. End Sub
    28.  
    29. Private Sub MSFlexGrid1_Scroll()
    30.   removeTxtCell
    31. End Sub
    32.  
    33. Private Sub MSFlexGrid1_SelChange()
    34.   removeTxtCell
    35. End Sub
    36.  
    37. Private Sub txtCell_Change()
    38.   MSFlexGrid1.Text = txtCell.Text
    39. End Sub
    40.  
    41. Private Sub showTxtCell()
    42.   If m_lCellRow = -1 Then
    43.     With MSFlexGrid1
    44.       ' store the current row and column
    45.       m_lCellRow = .Row
    46.       m_lCellCol = .Col
    47.       ' move the textbox to the correct cell
    48.       txtCell.Move .Left + .CellLeft, .Top + .CellTop, .CellWidth, .CellHeight
    49.       txtCell.Text = .Text
    50.       ' select all text
    51.       txtCell.SelLength = Len(.Text)
    52.     End With
    53.     txtCell.Visible = True
    54.     txtCell.SetFocus
    55.   End If
    56. End Sub
    57.  
    58. Private Sub removeTxtCell()
    59.   If m_lCellRow <> -1 Then
    60.     MSFlexGrid1.TextMatrix(m_lCellRow, m_lCellCol) = txtCell.Text
    61.     m_lCellRow = -1
    62.     m_lCellCol = -1
    63.     txtCell.Visible = False
    64.   End If
    65. End Sub
    66.  
    67. Private Sub txtCell_Validate(Cancel As Boolean)
    68.   removeTxtCell
    69. End Sub

    For this you will need to add a Textbox control called: txtCell also

    Not writtne by me...

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  3. #3

    Thread Starter
    Junior Member Jethro Tull's Avatar
    Join Date
    May 2005
    Location
    Buenos Aires - Argentina
    Posts
    31

    Re: Can I write in a FlexGrid?

    Thanks :b:

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