problem scrolling a msFlexGrid control

Posted on 2004-04-22
Last Modified: 2013-12-26
Hi, I wanted to be able to edit the first three colums of a MSFlexGrid control but also to fix these colums when scrolling to the right (they contain descriptions for the row).
So I coded this in the MSFlexGrid1_Scroll event:
with msflexGrid1
If .ColIsVisible(6) Then 'when column 6 appears it means
                                  'that there a was a shift
        .FixedCols = 3
        .FixedCols = 0
End If
end with

but now I cannot scroll vertically to the bottom of the grid.
I just can get to  row .Rows-2

Any clue?  Thank you very much.

Question by:rrgw
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Expert Comment

ID: 10897027

What i am getting is u have control (Text Box ) on first three col on each row. Now u want as user scroll it will also scroll with the appropriate col.

Let me correct if i am mistaking so we continue.

Amit Jian
LVL 11

Accepted Solution

dbrckovi earned 75 total points
ID: 10898179
Try this:

 - start new project
 - create MSFlexGrid and a CheckBox
 - paste this code:
Private Sub Check1_Click()
    If Check1.Value = 1 Then                    'Change flexgrid appearance to edit mode
        MSFlexGrid1.FixedCols = 0
        For X = 0 To 2
            MSFlexGrid1.Col = X
            For Y = MSFlexGrid1.FixedRows To MSFlexGrid1.Rows - 1
                MSFlexGrid1.Row = Y
                MSFlexGrid1.CellBackColor = vbButtonFace
            Next Y
        Next X
    Else                                        'Change appearance back to normal
        MSFlexGrid1.FixedCols = 3
        For X = 0 To 2
            MSFlexGrid1.Col = X
            For Y = MSFlexGrid1.FixedRows To MSFlexGrid1.Rows - 1
                MSFlexGrid1.Row = Y
                MSFlexGrid1.CellBackColor = vbButtonFace
            Next Y
        Next X
    End If
End Sub

Private Sub Form_Load()                       'Some initialisation
    MSFlexGrid1.Cols = 10
    MSFlexGrid1.Rows = 10
    MSFlexGrid1.FixedCols = 3
    Check1.Caption = "Edit mode"
    Check1.Value = 0
End Sub

Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)
    If Check1.Value = 0 Then Exit Sub                     'Ignore keypresses if not in edit mode
    If KeyAscii = vbKeyBack Then                          'Delete last character a cell
        If Len(MSFlexGrid1.Text) > 0 Then MSFlexGrid1.Text = Left(MSFlexGrid1.Text, Len(MSFlexGrid1.Text) - 1)
        GoTo CalculateWidth
    End If
    If KeyAscii = 13 Then                                   'If enter is pressed jump to cell to the right or jump to next row if this is the last cell in current row
        If MSFlexGrid1.Col = MSFlexGrid1.Cols - 1 Then
            If MSFlexGrid1.Row = MSFlexGrid1.Rows - 1 Then
                MSFlexGrid1.Row = MSFlexGrid1.Row + 1
                MSFlexGrid1.RowSel = 0
                MSFlexGrid1.Col = 0
                MSFlexGrid1.ColSel = MSFlexGrid1.Col
            End If
            MSFlexGrid1.Col = MSFlexGrid1.Col + 1
            MSFlexGrid1.ColSel = MSFlexGrid1.Col
        End If
        MSFlexGrid1.TopRow = MSFlexGrid1.Row
        MSFlexGrid1.LeftCol = MSFlexGrid1.Col
        Exit Sub
    End If
    MSFlexGrid1.Text = MSFlexGrid1.Text & Chr(KeyAscii)     'Add the character to current cell
CalculateWidth:                                             'Calculate new width of current collumn
    wasrow = MSFlexGrid1.Row
    LargestWidth = 0
    For X = 0 To MSFlexGrid1.Cols - 1
        MSFlexGrid1.Row = X
        If (Me.TextWidth(MSFlexGrid1.Text) + 200) > LargestWidth Then LargestWidth = (Me.TextWidth(MSFlexGrid1.Text) + 200)
    Next X
    MSFlexGrid1.ColWidth(MSFlexGrid1.Col) = LargestWidth
    MSFlexGrid1.Row = wasrow
End Sub
LVL 11

Expert Comment

ID: 10898228
To implement this into an existing Flex Grid it should be enough just to create Check1 and paste     Check1_Click()      and      MSFlexGrid1_KeyPress     subroutines (without Form_Load), but it depends on what you
already have in your project.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question