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

Posted on 2013-02-01
Last Modified: 2013-02-02
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.

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
            MSHFlexGrid2.CellBackColor = &H80000005
        End If
    Next myRow
End If

Open in new window

Question by:Wilder1626
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 15

Accepted Solution

eemit earned 500 total points
ID: 38846463

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

  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

LVL 11

Author Closing Comment

ID: 38846541
Thank you so much

This is perfect

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

728 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