Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB6 - Set focus in MSHFlexgrid1 cell problem

Posted on 2014-02-27
4
Medium Priority
?
387 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 49

Accepted Solution

by:
Martin Liss earned 2000 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 49

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

609 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