CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2009
    Posts
    100

    [RESOLVED] MSFlexGrid Not Highlighting Row

    I have an MSFlexGrid that I am manipulating in code, and everything works except for the highlighting of the row. I can set the row, and update other labels on the form based on the selected row, but the row itself does not highlight.

    If I click on the row, it does highlight. I have the highlight property set to Always, and as stated if I click on the row it highlights. But if when I use the following code, it does not highlight in either flexgrid:

    Code:
    Private Sub cmdRandomRoll_Click()
        Dim intTemp As Integer
        Dim rstRecords As ADODB.Recordset
        Dim strSelect As String
        
        Set rstRecords = New ADODB.Recordset
        
        intTemp = Generate_Random_Number(100, 1)
        strSelect = "SELECT ID FROM tblExperimentNature WHERE " & intTemp & " >= RollLow AND " & intTemp & " <= RollHigh"
        rstRecords.Open strSelect, adoHUConnection, adOpenKeyset, adLockOptimistic
        rstRecords.MoveFirst
        
        For intTemp = 0 To grdNature.Rows - 1
            If grdNature.TextMatrix(intTemp, 0) = rstRecords!ID Then
                grdNature.Row = intTemp
                grdNature.RowSel = grdNature.Row
                grdNature.SetFocus
                Call grdNature_Click
                Exit For
            End If
        Next
        
        rstRecords.Close
    
        intTemp = Generate_Random_Number(100, 1)
        strSelect = "SELECT ID FROM tblExperimentType WHERE " & intTemp & ">= RollLow AND " & intTemp & " <= RollHigh"
        rstRecords.Open strSelect, adoHUConnection, adOpenKeyset, adLockOptimistic
        rstRecords.MoveFirst
        
        For intTemp = 0 To grdType.Rows - 1
            If grdType.TextMatrix(intTemp, 0) = rstRecords!ID Then
                grdType.Row = intTemp
                Call grdType_Click
                Exit For
            End If
        Next
        
        rstRecords.Close
        Set rstRecords = Nothing
    End Sub
    You will see a few subroutines being called that I did not include, but these only generate a random number or populate a label on the form.

    You'll also see that I'm selecting the row in 2 different ways:

    1. grdNature.Row is set, then grdNature.RowSel is set, and then grdNature gets focus; AND

    2. grdType.Row is set

    Anybody know why the row is not being selected with the above code? Can somebody tell me what I'm doing wrong?

  2. #2
    Join Date
    Aug 2009
    Posts
    100

    Re: MSFlexGrid Not Highlighting Row

    And...resolved. I used a loop in the Grid_Click event to wipe out any current highlighted cells, and then set the selected row/cell back color. Drove me nuts all day, but I got it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured