datagrid vs MsFlexgrid

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
LVL 4
claracruzAsked:
Who is Participating?
 
dancebertConnect With a Mentor Commented:
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
 
SethiConnect With a Mentor Commented:
1) True. It's possible
2) False. Not possible as there is not corresponding property or method for this.
0
 
claracruzAuthor Commented:
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
amit1978Commented:
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
 
claracruzAuthor Commented:
yes please, that is exactly what I need, the code for the methods I listed.

thank you
0
 
dancebertConnect With a Mentor Commented:
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
 
claracruzAuthor Commented:
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
 
claracruzAuthor Commented:
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
 
R_K_T_ASHOKACommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.