Link to home
Start Free TrialLog in
Avatar of DelphiCurious
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

Avatar of Mohammed Nasman
Mohammed Nasman
Flag of Palestine, State of image

Hello

  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.RowFilter = ...

if you want to clear the Filter just set the RowFilter property to empty string

HTH

Regards,
Mohammed Nasman
Avatar of DelphiCurious
DelphiCurious

ASKER

it works but it searches the first column and i want to search the third
ASKER CERTIFIED SOLUTION
Avatar of Mohammed Nasman
Mohammed Nasman
Flag of Palestine, State of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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