Solved

VB6 - Set focus in MSHFlexgrid1 cell problem

Posted on 2014-02-27
4
378 Views
Last Modified: 2014-02-28
Hi

I have this below macro that search  If MSHFlexGrid1.TextMatrix(i, 2) = new_user.Text.

What i'm trying to do it to get focus on the cell in the MSHFlexgrid that have the same value from new_user.Text if there is a match.

How can i do that?

Thanks for your help.

 Dim i As Long
    For i = 1 To MSHFlexGrid1.Rows - 1

           If MSHFlexGrid1.TextMatrix(i, 2) = new_user.Text Then

'MSHFlexGrid1.SetFocus

            MsgBox "User already exist"

            Exit Sub

        Else

        End If
    Next

Open in new window

0
Comment
Question by:Wilder1626
  • 2
  • 2
4 Comments
 
LVL 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 39893872
To highlight the cell you could do something like this.

Dim i As Long
    For i = 1 To MSHFlexGrid1.Rows - 1

           If MSHFlexGrid1.TextMatrix(i, 2) = new_user.Text Then

            MSFlexGrid1.Row = i
            MSFlexGrid1.Col = 2
            MSFlexGrid1.CellBackColor = vbRed


            MsgBox "User already exist"

            Exit Sub

        Else

        End If
    Next

Open in new window


And to turn it off change the BackColor to 0.
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 39894276
Can we make it to go on the specific cell with the same value right away? Just like the .SetFocus!
0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 39894313
Perfect, Thanks again, its working now:

                    If MSHFlexGrid1.TextMatrix(i, 2) = new_user.Text Then

                        MSHFlexGrid1.Row = i
                        MSHFlexGrid1.Col = 2
                        MSHFlexGrid1.CellBackColor = vbRed

                        MSHFlexGrid1.Redraw = True    'this must be set before setting TopRow !!!
                        MSHFlexGrid1.TopRow = i
                        'set focus back to grid
                        MSHFlexGrid1.SetFocus

                        MsgBox "Request already exist"

                        Exit Sub

                    Else

                        MSHFlexGrid1.Row = i
                        MSHFlexGrid1.Col = 2
                        MSHFlexGrid1.CellBackColor = vbWhite


                    End If
                Next
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 39894770
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2013
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now