Results 1 to 5 of 5

Thread: [RESOLVED] How to check if item your trying to input is in flexgrid

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2009
    Posts
    33

    Resolved [RESOLVED] How to check if item your trying to input is in flexgrid

    I want to check if the item im trying to input is in the flexgrid

    example i have a keypress on textbox1

    ill input 1 on that textbox, when i press enter it will check if it is already in the flexgrid else if its not, it will display what i inputted on textbox1.

    could really need some help on this one

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: How to check if item your trying to input is in flexgrid

    Loop through every Cell in the FlexGrid and compare its value to the TextBox value.

    Code:
        
        Dim row As Long
        Dim col As Long
        Dim exists as boolean
    
        With Me.MSFlexGrid1
            For row = .FixedRows To .Rows - 1
                For col = .FixedCols To .Cols - 1
                     'use vbBinaryCompare for a Case Sensitive search
                     If StrComp(Text1.Text, Me.MSFlexGrid1.TextMatrix(row, col), vbTextCompare) = 0 Then
                        MsgBox "Data already exists in grid"
                        exists = True
                        Exit For
                     End If
                Next
                If exists Then Exit For 'already found the data no need to continue the loop
            Next
    
            If Not exists then
                MsgBox "Need to add data to the grid. The question is where?"
            End If
        End With

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2009
    Posts
    33

    Re: How to check if item your trying to input is in flexgrid

    Quote Originally Posted by brucevde
    Loop through every Cell in the FlexGrid and compare its value to the TextBox value.

    Code:
        
        Dim row As Long
        Dim col As Long
        Dim exists as boolean
    
        With Me.MSFlexGrid1
            For row = .FixedRows To .Rows - 1
                For col = .FixedCols To .Cols - 1
                     'use vbBinaryCompare for a Case Sensitive search
                     If StrComp(Text1.Text, Me.MSFlexGrid1.TextMatrix(row, col), vbTextCompare) = 0 Then
                        MsgBox "Data already exists in grid"
                        exists = True
                        Exit For
                     End If
                Next
                If exists Then Exit For 'already found the data no need to continue the loop
            Next
    
            If Not exists then
                MsgBox "Need to add data to the grid. The question is where?"
            End If
        End With
    thanks! ill try it

    col is fixed by the way. it will be added in the first column always, after the item is added the row will be incremented by 1 and col will always stay in 1.

    the item will be added in the next available space.

    EDIT: thanks!, really worked, got 1 question, what is .FixedRows?
    Last edited by enjoyincubus; Feb 20th, 2009 at 11:09 PM.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: How to check if item your trying to input is in flexgrid

    .FixedRows/.FixedCols are the number of header rows/columns, which don't scroll (normally shown in grey rather than the white of the normal cells).

    As row/column numbers start at 0, the first data row/column will always be .FixedRows/.FixedCols

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2009
    Posts
    33

    Re: How to check if item your trying to input is in flexgrid

    ok thanks

Posting Permissions

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



Click Here to Expand Forum to Full Width