How to highlight a record in a MSHFlexGrid?-VBForums
Results 1 to 8 of 8

Thread: How to highlight a record in a MSHFlexGrid?

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    41

    How to highlight a record in a MSHFlexGrid?

    I have a MSHFlexGird (fgdCompany) and a search command. When the user enters the search data into "txtSearch", the command should search for the data and show it to the user by :

    Highlighting the record in the MSHFlexGrid
    -OR-
    By bringing the row that contains the searched data to the top of the MSHFlexGrid.

    The code that I am using is given below. The search function works perfectly. Only thing is I can't make the record that contains the searched data be highlighted so that the user knows in which record the data that was search data is present. Can anybody could give me the code to highlight the record found in any of the two methods given above (preferably the first option).
    Code:
        Dim xString As String, xRow As Integer, xNext As Integer
        
        xString = txtSearch.Text
        For xNext = 0 To fgdCompany.Rows
        fgdCompany.Row = xNext
        xRow = fgdCompany.Row
        If xString = fgdCompany.TextMatrix(xRow, 1) Then 'Assuming that the string to be searched is in coloumn 1...
        myRow = fgdCompany.Row
        Exit For
        End If
        Next xNext

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,357

    Re: How to highlight a record in a MSHFlexGrid?

    I just did on your original post......let me know if that works......

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    41

    Re: How to highlight a record in a MSHFlexGrid?

    Quote Originally Posted by SamOscarBrown View Post
    I just did on your original post......let me know if that works......
    hi. When I run the program it gives the error "Next without For" and when clicked debug, it highlights the line "Next x"

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,357

    Re: How to highlight a record in a MSHFlexGrid?

    argh....hate copy-paste....(change all MSHFlexgrid1 to MSFlexgrid1 (my code uses MSHF....)

    here:

    For X = 0 To MSHFlexGrid1.Cols - 1
    MSHFlexGrid1.Col = X
    For Y = 1 To MSHFlexGrid1.Rows - 1
    MSHFlexGrid1.Row = Y
    MSHFlexGrid1.CellBackColor = vbYellow 'assuming vbYellow is original BG color
    Next Y
    Next X
    For Z = 0 To MSHFlexGrid1.Cols - 1
    MSHFlexGrid1.Col = Z
    MSHFlexGrid1.Row = rownumber1
    MSHFlexGrid1.CellBackColor = vbGreen
    Next Z

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    41

    Re: How to highlight a record in a MSHFlexGrid?

    I'm currently using this code.
    Code:
        xString = txtSearch.Text
        For xNext = 0 To fgdCompany.Rows
        fgdCompany.Row = xNext
        xRow = fgdCompany.Row
        If xString = fgdCompany.TextMatrix(xRow, 1) Then
        myRow = fgdCompany.Row
        fgdCompany.TopRow = myRow
        
        Exit For
        End If
        Next xNext
    Can you please say me where I should insert the code you have given above.
    (fgdCompany is the name of my MSHFlexGrid)
    And how do I find out my original BG color?
    Last edited by Skate Bart; Sep 7th, 2012 at 11:18 AM.

  6. #6

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    41

    Re: How to highlight a record in a MSHFlexGrid?

    Quote Originally Posted by SamOscarBrown View Post
    argh....hate copy-paste....(change all MSHFlexgrid1 to MSFlexgrid1 (my code uses MSHF....)

    here:

    For X = 0 To MSHFlexGrid1.Cols - 1
    MSHFlexGrid1.Col = X
    For Y = 1 To MSHFlexGrid1.Rows - 1
    MSHFlexGrid1.Row = Y
    MSHFlexGrid1.CellBackColor = vbYellow 'assuming vbYellow is original BG color
    Next Y
    Next X
    For Z = 0 To MSHFlexGrid1.Cols - 1
    MSHFlexGrid1.Col = Z
    MSHFlexGrid1.Row = rownumber1
    MSHFlexGrid1.CellBackColor = vbGreen
    Next Z
    OMG OMG!!! It worked. I tweaked the code a little bit with the one you gave above and it works perfectly.
    But the problem is, it only highlights the first column of the row that the searched data was found. I want it to highlight the whole row.
    Any ideas?
    Here's the Code I'm using now :

    Code:
        xString = txtSearch.Text
        For xNext = 0 To fgdCompany.Rows
        fgdCompany.Row = xNext
        xRow = fgdCompany.Row
        If xString = fgdCompany.TextMatrix(xRow, 1) Then
        myRow = fgdCompany.Row
        fgdCompany.RowSel = myRow
        fgdCompany.CellBackColor = vbGreen
           
        Exit For
        End If
        Next xNext

  7. #7
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,357

    Re: How to highlight a record in a MSHFlexGrid?

    Create a private subroutine (I called my HIGHLIGHTING). Call that function after this line: fgdCompany.TopRow = myRow.
    To find the original backcolor.....look at the properties of your MSFlexgrid, and find the one called 'backcolor'. You can use the hexidecimal to reset, or RGB equivalent, or VBs Constants.
    I use a free application (colorpicker) to find ANY RGB color.....to make it easy, set your grid's backcolor at initialization to someting like vbWhite, then you can use another VB Constant (liek vbGreen) to highlight

    xString = txtSearch.Text
    For xNext = 0 To fgdCompany.Rows
    fgdCompany.Row = xNext
    xRow = fgdCompany.Row
    If xString = fgdCompany.TextMatrix(xRow, 1) Then
    myRow = fgdCompany.Row
    fgdCompany.TopRow = myRow
    CALL HIGHLIGHTING
    Exit For
    End If
    Next xNext

    Private Sub highlighting()
    For X = 0 To MSFlexGrid1.Cols - 1
    MSFlexGrid1.Col = X
    For Y = 1 To MSFlexGrid1.Rows - 1
    MSFlexGrid1.Row = Y
    MSFlexGrid1.CellBackColor = vbYellow 'assuming vbYellow is original BG color
    Next Y
    Next X
    For Z = 0 To MSFlexGrid1.Cols - 1
    MSFlexGrid1.Col = Z
    MSFlexGrid1.Row = rownumber1
    MSFlexGrid1.CellBackColor = vbGreen
    Next Z
    END SUB

  8. #8
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,357

    Re: How to highlight a record in a MSHFlexGrid?

    sorry...change all MSFLEXGrid1's to "fgdCompany"

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.