VB6 - Select value from grid and highlight same value in grid 2

Hello all

I would like to be able to select a row in my MSHFlexgrid1 and from that specific row, it would search for the value in column 4 into the MSHFlexgrid2 column 1. If there is a perfect match, it would select the MSHFlexgrid2 row and put the column: MSHFlexGrid2.CellBackColor = &H80FF& in the column 1.

Ex:
if i select MSHFlexgrid1 row 5, in column 4 i have the value: TEST1

If in my MSHFlexgrid2 row 27 column 1 i also have the value: TEST1, it would select that row and add the backcolor in the cell : MSHFlexGrid2.CellBackColor = &H80FF&


How can i do that?

Thanks again for your help


Dim LastMatch
Dim myRow
On Error Resume Next
    
    For myRow = LastMatch To MSHFlexGrid2.Rows
        If MSHFlexGrid2.TextMatrix(myRow, 1) = MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 4) Then
            MSHFlexGrid2.TopRow = myRow
            MSHFlexGrid2.Row = myRow
            MSHFlexGrid2.Col = 1
            MSHFlexGrid2.CellBackColor = &H80FF&
            Exit Sub
            Else
            MSHFlexGrid2.CellBackColor = &H80000005
        End If
    Next myRow
    
End If

Open in new window

LVL 11
Wilder1626Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
eemitConnect With a Mentor Commented:
Try:

Private Sub Form_Load()
  MSHFlexGrid1.Row = 0
End Sub

Private Sub MSHFlexGrid1_RowColChange()
  On Error GoTo Err_Handler
  
  Dim myRow As Long
      
  Dim sSearch As String
  With MSHFlexGrid1
      sSearch = .TextMatrix(.Row, 4)
  End With
  
  Call ResetColumnBColor
  
  With MSHFlexGrid2
      For myRow = 1 To .Rows - 1
          If .TextMatrix(myRow, 1) = sSearch Then
              .TopRow = myRow
              .Row = myRow
              .Col = 1
              .CellBackColor = &H80FF&
          End If
      Next myRow
  End With
  
  Exit Sub

Err_Handler:
  Debug.Print "ERROR (MSHFlexGrid1_RowColChange): " & CStr(Err.Number) & ", " & Err.Description

End Sub


Private Sub ResetColumnBColor()
  Dim myRow As Long
  
  With MSHFlexGrid2
      For myRow = 1 To .Rows - 1
          .Row = myRow
          .Col = 1
          .CellBackColor = &H80000005
      Next myRow
  End With
End Sub

Open in new window

0
 
Wilder1626Author Commented:
Thank you so much

This is perfect
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.