Solved

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

Posted on 2013-02-01
2
505 Views
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.

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

0
Comment
Question by:Wilder1626
2 Comments
 
LVL 15

Accepted Solution

by:
eemit earned 500 total points
ID: 38846463
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
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 38846541
Thank you so much

This is perfect
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Basic Excel Formatting error 4 102
vb6 connector to mongodb 2 81
using web browser with BING 40 119
Access Object Property from VBA Module in Excel 2010 2 31
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

774 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