Solved

VB6 - Set focus in MSHFlexgrid1 cell problem

Posted on 2014-02-27
4
376 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 45

Accepted Solution

by:
Martin Liss earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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 45

Expert Comment

by:Martin Liss
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

771 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

13 Experts available now in Live!

Get 1:1 Help Now