Solved

problem scrolling a msFlexGrid control

Posted on 2004-04-22
3
601 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access 2003, my txt file export is running backwards 4 52
TT Auto Dashboard 13 92
How to read File Date Created using VB6 8 40
Formula problem with Excel attachment 6 28
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

832 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