Solved

VB6 - Set focus in MSHFlexgrid1 cell problem

Posted on 2014-02-27
4
382 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
[X]
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
  • 2
  • 2
4 Comments
 
LVL 47

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 47

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

726 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