424,054 Members | 1,055 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,054 IT Pros & Developers. It's quick & easy.

Search record in DataGrid

P: n/a
HS1
Hello all

I use a DataGrid to present the data of an Access database table ("Clients")
using DataAdapter and DataSet (ds)
-----------------------------------------------------------
DataGrid1.DataMember = "Clients"

DataGrid1.DataSource = ds

----------------------------------------------------------------------------
-------

I also have some button "Next". When I click in this button, I can go to the
next record in DataGrid1:
Private Sub NextButton_Click(......)

Me.BindingContext(DataGrid1.DataSource, "Clients").Position += 1
Now I have to create a button "Search". To do that I use a DataView as the
following code:
-----------------------------------------------------------------
Private Sub SearchButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles SearchButton.Click

Dim cm As CurrencyManager

Dim dv As DataView = New DataView(ds.Tables("Clients"))

cm = CType(Me.BindingContext(dv), CurrencyManager)

DataGrid1.DataSource = dv

dv.Sort = "Name"

Dim int As Integer

int = dv.Find(Text_search.Text)

If int >= 0 Then

cm.Position = int

Else : MessageBox.Show(" Not Found ")

End If

End Sub

------------------------
It can be seen that when I use the search button, I change
DataGrid.DataSource from DataSet(ds) to DataView(dv). The problem here is
that after searching a record, when I click on "Next" button, I cannot go to
next record anymore event I set again the DataSource in the event hander of
this button:
Private Sub NextButton_Click(....)
DataGrid1.DataSource = ds
DataGrid1.DataMember = "Clients"

Do you know the best way to solve this problem

Thank you

Hoa


Nov 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.