John,
Here's some code I came up with recently to help a friend with a similar
requirement.
It allows a wildcard search and returns all rows in which the search
string is found. Can also be easily adapted to include partial string
matches. The way it is set up now it creates a cloned copy of the schema
of the original DataTable, then runs the search, adding to the cloned table
any rows of the original table in which it finds a match. Once all the
original Table's rows have been searched, a datagrid is populated with the
contents of the cloned table - ie, a datagrid full of matches.
I know this is not exactly the way you have described what you are doing,
but if this is any use to you for your project,here is the code.
Code:
DataGrid1.DataSource = Nothing ' Clear display in datagrid
Dim DTOriginal As DataTable = DS.Tables(0) ' Get source datatable
' Create new DataTable by cloning structure of original
Dim DTCloned As DataTable = DTOriginal.Clone
' Import the matching DataRows into the cloned Table
Dim drtemp As DataRow
Dim j As Integer
' Enumerate through all rows
For Each drtemp In DTOriginal.Rows
' and within each row iterate through all columns
For j = 0 To DTOriginal.Columns.Count - 1
' If you find a match ..
If drtemp.Item(j).ToString = Trim(txtSearch.Text) Then
' add this row to the new DataTable
DTCloned.ImportRow(drtemp)
' and stop looking along this row
Exit For
End If
Next
Next
' Update Grid with new table
DataGrid1.DataSource = DTCloned
End Code
Hope this helps
Ged
[quoted text, click to view] "John Hernry" <john.henry@sasktel.com> wrote in message
news:%23yiCZXrvEHA.1400@TK2MSFTNGP11.phx.gbl...
> I have a datagrid that is bound to a dataview. I am looking to create a
> form that will perform wildcard searches on the dataview and move the
> datagrid to the found row.
>
> I can get the find to work in that it returns a valid row, but it is not
the
> first row with that value. I suspect that it is because it is not a
unique
> value in that column. I also can't perform wildcard searches.
>
> Here is my search code
> Dim dvData As DataView
> Dim cmBkMrk As CurrencyManager
>
> dvData = Me.dgrCatalogue.DataSource
> dvData.Sort = "Artist"
> cmBkMrk = Me.dgrCatalogue.BindingContext(dvData)
> cmBkMrk.Position = dvData.Find("Triumph")
> Me.dgrCatalogue.Select(cmBkMrk.Position)
>
> If you have ever used the find in Access I am trying to build something
> along that line. Where I can specify criteria such as: search in one
field,
> all fields, at the beginning of the field, end of the field, must match
the
> entire field, or case sensitive etc. My database currently has 30,000
> records with 5 fields: ID, Source, Song, Artist, Album. ID is the primary
> key.
>
> I suspect that I am going to have to create a second dataview of the
table,
> do a filter on it, find the record I need (which will likely have to still
> be done by looping through the filtered records, but at least far less of
> them), get the unique ID from the found record then find that ID on the
> displayed dataview and move to that record. . I was hoping for a quicker
> method as this method will be slow.
>
>
> Thank you in advance
>
> John
>
>