DelphiCurious
asked on
searching through datagrid
I have one datagrid thats populated with xml data. I want to have a text box to allow a user to search through datagrid 1 and dispaly the found results in datagrid2. can some1 give me some example code. would i just use the same as the datagrid 1 and use filter function?(I would prefer using the same dataset cause i want to allow user to change at later stages
ASKER
it works but it searches the first column and i want to search the third
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Is there a way someone could help me out with my problem? Kinda the same thing. What I previously have had one expert help me with, has really not helped much.
https://www.experts-exchange.com/questions/21284699/Search-datagrid-question.html
https://www.experts-exchange.com/questions/21284699/Search-datagrid-question.html
Use dataView to help you to accomplish that
Here's an example to show all data from xml file in dataGrid1, and the search for a value and show the result in dataGrid2
...... Windows Form Designer generated code
Dim ds As New DataSet
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dv As New DataView(ds.Tables(0))
dv.RowFilter = "FirstName = '" & TextBox1.Text & "'"
DataGrid2.DataSource = dv
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ds.ReadXml("c:\emp.xml")
DataGrid1.DataSource = ds.Tables(0)
End Sub
If you would like the result to showed in the same grid, you can use the Default DataView of DataTable
as
Ds.Tables(0).DefaultView.R
if you want to clear the Filter just set the RowFilter property to empty string
HTH
Regards,
Mohammed Nasman