[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 :(
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
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?
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
Re: How to check if item your trying to input is in flexgrid