Solved

VB6 - Set focus in MSHFlexgrid1 cell problem

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

803 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