Solved

problem scrolling a msFlexGrid control

Posted on 2004-04-22
3
595 Views
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:
<vb>
with msflexGrid1
If .ColIsVisible(6) Then 'when column 6 appears it means
                                  'that there a was a shift
        .FixedCols = 3
Else
        .FixedCols = 0
End If
end with
</vb>

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.

rr.
0
Comment
Question by:rrgw
  • 2
3 Comments
 
LVL 5

Expert Comment

by:amit1978
ID: 10897027
Hi,

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
0
 
LVL 11

Accepted Solution

by:
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
            Else
                MSFlexGrid1.Row = MSFlexGrid1.Row + 1
                MSFlexGrid1.RowSel = 0
                MSFlexGrid1.Col = 0
                MSFlexGrid1.ColSel = MSFlexGrid1.Col
            End If
        Else
            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
--------------------------------------------------
0
 
LVL 11

Expert Comment

by:dbrckovi
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.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now