|
-
Jul 15th, 2004, 01:57 AM
#1
Thread Starter
Frenzied Member
search a value from datagrid w/ the use of textbox value.
hi to everyone,
i have this problem.how can i search to the datagrid w/ the use of textbox value.
lets assumed that the datagrid were bound a data.
f.e. when the user input a name in the textbox and press the enterkey it will get focus to the datagrid on what value is in the textbox.
a sort of comboboxautocomplete but not as good as that.
hope i explain it will
thanks in advance guys.
and more power.
sorry im english is weak.
-
Jul 15th, 2004, 06:56 AM
#2
Hyperactive Member
Hi
Is that not just a simple text search on the datagrid? This would then show the row selected (ie have focus)
Danny
-
Jul 15th, 2004, 08:17 PM
#3
Thread Starter
Frenzied Member
yes. i want to search to the datagrid on what value is in the textbox.
f.e. the value of textbox = Gangster.
so..in the datagrid it will get focus to the Gangster value.
i cant figure it out.
pls.help its very important to me.
thanks in advance and more power.
-
Jul 16th, 2004, 02:59 AM
#4
Hyperactive Member
Hi Mate
I would assume you would do something similar to the following!
Dim sStr As String
Dim sTestStr As String
Dim bfound as boolean
sTestStr = textbox.text.ToUpper
For i = 0 to datagrid.col
for j = 0 to datagrid.row
sStr = CType(datagrid.item(i,j), String).ToUpper
if sStr = sTestStr then
bfound = true
datagrid.row = j
exit for
end if
next
if bfound then exit for
next
The syntax maybe a little off but you should be able to modify it!
Cheers
Danny
-
Jul 16th, 2004, 04:14 AM
#5
Thread Starter
Frenzied Member
hi mate...thanks for the reply
i tried your code but it wont work.
VB Code:
Dim s, ss As String
Dim f As Boolean
Dim i, j As Integer
ss = TextBox1.Text.ToUpper
For j = 0 To DataGrid1.CurrentCell.ColumnNumber
For i = 0 To DataGrid1.CurrentCell.RowNumber
s = CType(DataGrid1.Item(i, j), String).ToUpper
If s = ss Then
f = True
Exit For
End If
Next
If f Then Exit For
Next
what's wrong w/ it?
thanks in advance mate.
-
Jul 16th, 2004, 07:31 AM
#6
Member
Take this, put it in a class such as a utility class pass it the value of the text box as well as the other specified values. It will do dates or strings.
Public Sub searchDatagrid(ByVal dg As DataGrid, ByVal rowCount As Integer, ByVal txt As String, ByVal col As Integer, Optional ByVal all As Boolean = False)
'Searches for and selects an item in the datagrid based on the sent text.
Dim r As Integer
Dim s As Integer
Dim found As Boolean
Dim csc As GridColumnStylesCollection
Dim gcs As DataGridColumnStyle
Dim w As Integer
csc = dg.TableStyles(0).GridColumnStyles
Try
dg.UnSelect(dg.CurrentRowIndex)
If txt.Length = 0 Then
dg.CurrentRowIndex = 0
dg.Select(dg.CurrentRowIndex)
Exit Sub
End If
If Not all Then
w = csc(col).Width
csc(col).Width = 1
End If
If UCase(txt) <= UCase(Mid(dg.Item(dg.CurrentRowIndex, col), 1, Len(txt))) _
Or all = True Then
s = 0
Else
's = cm.Position
End If
For r = s To rowCount - 1
If all = True Then
'This looks in all columns
'csc = dg.TableStyles(0).GridColumnStyles
col = 0
For Each gcs In csc
Try
If dg.Item(r, col).GetType.ToString = "System.DateTime" Then
found = Format(dg.Item(r, col), "MM/dd/yyyy") Like UCase(txt) & "*"
Else
found = UCase(dg.Item(r, col)) Like UCase(txt) & "*"
End If
If found Then
dg.CurrentRowIndex = r
Exit For
End If
col += 1
Catch
End Try
Next
If found Then Exit For
Else
Try
If dg.Item(r, col).GetType.ToString = "System.DateTime" Then
found = Format(dg.Item(r, col), "MM/dd/yyyy") Like UCase(txt) & "*"
Else
found = UCase(dg.Item(r, col)) Like UCase(txt) & "*"
End If
If found Then
dg.CurrentRowIndex = r
Exit For
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
Next
If Not all Then
csc(col).Width = w
End If
dg.Select(dg.CurrentRowIndex)
Catch ex As Exception
End Try
End Sub
Any ?'s let me know. And yes, it works.
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
|