Solved

datagrid vs MsFlexgrid

Posted on 2004-04-05
9
53,450 Views
Last Modified: 2013-12-25
Hello experts,

I have a couple of questions on MsFlexgrid, I have been using Datagrid, and need to swap over, so the questions;-

1.) Is it possible to do a fullrowselect in MsFlexgrid.
2.) Is there an AllowArrows = True method for MsFlexgrid

If these are possible, how do I do this?

thank you
0
Comment
Question by:claracruz
9 Comments
 
LVL 9

Accepted Solution

by:
dancebert earned 100 total points
ID: 10761617
1 is true, if I understand your question.  I have code that does the following: 1) click on fixed column (column # 0) and the row is highlighted.  2) Click on fixed column in a highlighted row and the row highlighting is removed.  3) Highlight one row, press shift and click on the fixed column of another row and all the rows in between are highlighted.  In all three cases, once a row is highlighted, clicking on any cell that is not in the fixed column will turn off all highlighting.  

If this is what you are trying to do, I can post a working example.
0
 
LVL 18

Assisted Solution

by:Sethi
Sethi earned 25 total points
ID: 10762314
1) True. It's possible
2) False. Not possible as there is not corresponding property or method for this.
0
 
LVL 4

Author Comment

by:claracruz
ID: 10763973
yes please, post a working example for a fullrowselect.
And also since 'AllowArrow = true' is not available in MsFlexgrid, is it at all possible for a user to move from one row to the next row down, without using the mouse.
0
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 5

Expert Comment

by:amit1978
ID: 10764142
Hi claracruz,

FlexGrid is much batter option then dbgrid as its static and no addition and deletion is not possible and ya also no updation. but ......but .......every thing is posible in flexgrid but u have to code for that thats the difference between flexgrid and dbgrid u there is not requirement of coding .

if u required code then may be i can help u.....


Amit Jain
0
 
LVL 4

Author Comment

by:claracruz
ID: 10764957
yes please, that is exactly what I need, the code for the methods I listed.

thank you
0
 
LVL 9

Assisted Solution

by:dancebert
dancebert earned 100 total points
ID: 10766782
Add a MSFlexGrid to a form, copy the following code into it.  Click on fixed column (column 0) to toggle row highlight.  Also supports Shift-Click and Ctrl-Click, which acts the same way as those keys in Windows Explorer.

==================  

Private m_IsOnFixedPart As Boolean
Private m_IsZeroRow As Boolean


Private Sub Form_Load()
' Begin sample grid setup code
            With MSFlexGrid1
                .Cols = 4
                .Rows = 10
                .FixedCols = 1
                .FixedRows = 1

                .Row = 0
                .TextMatrix(0, 1) = "Col1"
                .TextMatrix(0, 2) = "Col2"
                .TextMatrix(0, 3) = "Col3"

                Dim ii As Long
                For ii = 1 To 9
                    .TextMatrix(ii, 0) = ii
                    .TextMatrix(ii, 1) = CStr(CInt(Rnd * 10000))
                    .TextMatrix(ii, 2) = Chr(CInt(Asc(Rnd * 122) + 65))
                    .TextMatrix(ii, 3) = DateAdd("d", CInt(Rnd * 100), Date)
                Next ii

                ' Size the fixed column.
                .ColWidth(0) = 400
                .ColAlignment(0) = flexAlignCenterCenter
            End With
' End sample grid setup code at end.

End Sub

Private Sub ToggleSelect()
 'Toggle the select in the clicked row
    With MSFlexGrid1
        .Row = .MouseRow
        .FillStyle = flexFillRepeat
        .Col = .FixedCols
       
        .ColSel = .Cols - 1
        .HighLight = flexHighlightNever
        If .CellBackColor = vbHighlight Then
            .CellBackColor = .BackColor
            .CellForeColor = .ForeColor
        Else
            .CellBackColor = vbHighlight
            .CellForeColor = vbHighlightText
        End If
    End With
End Sub

Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    ' Are we on fixed column?  If so, highlight row(s)
   
    With MSFlexGrid1
        If .Rows = 0 And .Cols = 0 Then
            Exit Sub
        End If
       
        ' After deselecting rows, need these to get back to original cell
        Dim lRowOriginal As Long: lRowOriginal = .MouseRow
        Dim lColOriginal As Long: lColOriginal = .MouseCol
   
        ' Don't understand this, the code was downloaded.
        Dim l As Long
        Dim lWidth As Long
        For l = 0 To .Cols - 1
            If .ColIsVisible(l) Then
                lWidth = lWidth + .ColWidth(l)
            End If
        Next
       
        If .RowHeightMin = 0 Then
            m_IsOnFixedPart = (x < .ColWidth(0)) Or _
                       (x > lWidth) Or _
                       (y < .RowHeight(0))
        Else
            m_IsOnFixedPart = (x < .ColWidth(0)) Or _
                       (x > lWidth) Or _
                       (y < .RowHeight(0)) Or _
                       (y > .Rows * .RowHeightMin)
        End If
                       
        m_IsZeroRow = (.RowHeight(0) >= y)
       
       
        '' Highlighting
        If Not m_IsOnFixedPart Or m_IsZeroRow Then
            DeselectAllRows
            .Row = lRowOriginal
            .Col = lColOriginal
        Else
            If (Shift And vbShiftMask) = vbShiftMask Then
                SelectContigious 'Select from the current row to the clicked row
            ElseIf (Shift And vbCtrlMask) = vbCtrlMask Then
                ToggleSelect  'Toggle the select in the clicked row
            Else
                 DeselectAllRows
               
                'select clicked row
                 .RowSel = .Row
                 .ColSel = .Cols - 1
                .CellBackColor = vbHighlight
                .CellForeColor = vbHighlightText

            End If  '' If (Shift And vbShiftMask) = vbShiftMask Then
        End If  '' If Not m_IsOnFixedPart Or m_IsZeroRow Then
    End With

End Sub

Private Sub DeselectAllRows()
   
    Dim lRowOriginal As Long
    With MSFlexGrid1
        lRowOriginal = .Row
        .Row = .FixedRows
        .Col = .FixedCols
        .RowSel = .Rows - 1
        .ColSel = .Cols - 1
        .FillStyle = flexFillRepeat
       
        .HighLight = flexHighlightNever
        .CellBackColor = .BackColor
        .CellForeColor = .ForeColor
        .Row = lRowOriginal
        .ColSel = .Cols - 1
    End With

End Sub

Private Sub SelectContigious()
'Select from the current row to the clicked row
    Dim lRow As Long
    Dim lMouseRow As Long

    With MSFlexGrid1
        lRow = .Row
        lMouseRow = .MouseRow
        .FillStyle = flexFillRepeat
        .Row = lRow
        .Col = .FixedCols
        .RowSel = lMouseRow
        .ColSel = .Cols - 1
        .HighLight = flexHighlightNever
        .CellBackColor = vbHighlight
        .CellForeColor = vbHighlightText
    End With
End Sub

0
 
LVL 4

Author Comment

by:claracruz
ID: 10769648
I am sorry but I don't think this is what I need.

I have an SQL query that looks like this;

strDates = "SELECT [First Name], [Last Name], Players.[Date Of Birth], WHERE [Course Code]= '" & .DataGrid1.Columns(0) & "'    

what would be the equivalent of -  '" & .DataGrid1.Columns(0) & "'- when using an MsFlexgrid.

My other question is this:-
With the datagrid, I can move from one row to the next (and mimic the datagrid's click event ) using up or down arrows (and NOT the mouse) by setting AllowArrow property to "True", How do I do this with the MsFlexgrid.
0
 
LVL 4

Author Comment

by:claracruz
ID: 10773020
My question has been answered by RIMVIS,  posted at;-

(http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/VB_Controls/Q_20946101.html)

1)
To get value of MSFlexGrid cell, use TextMatrix property
TextMatrix(rowindex, colindex) [=string]

To get current row and columd, use Row and Col properties respectively.

So, value of current cell wil be MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, MSFlexGrid1.Col)

2)
You can navigate in flex grid using arrow keys without any additional code.
If you want to have entire row selected, set SelectionMode to 1 (select by row)


But thank you for all your contributions...

0
 

Expert Comment

by:R_K_T_ASHOKA
ID: 10842921
Hai,
     I have done a tutorial on how to use Flexgrid as Datagrid you can get it on the folowing link.

http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=42344&lngWId=1

Inform me if it is usefull.

Bye Bye,
R.K.T. ASHOKA.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA: Select SQL query based on a config Sheet v2 11 44
How to produce a SHA-1 hash function in vb6 in order to save it to a table 8 42
Spell Check in VB6 13 112
MsgBox 4 59
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

770 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