|
-
Feb 20th, 2009, 10:12 AM
#1
Thread Starter
Member
[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
-
Feb 20th, 2009, 10:34 AM
#2
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
-
Feb 20th, 2009, 07:28 PM
#3
Thread Starter
Member
Re: How to check if item your trying to input is in flexgrid
 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.
-
Feb 21st, 2009, 01:33 PM
#4
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
-
Feb 21st, 2009, 07:41 PM
#5
Thread Starter
Member
Re: How to check if item your trying to input is in flexgrid
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|