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
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

831 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