Solved

searching through datagrid

Posted on 2004-08-28
4
150 Views
Last Modified: 2010-08-05
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

0
Comment
Question by:DelphiCurious
  • 2
4 Comments
 
LVL 22

Expert Comment

by:mnasman
ID: 11924811
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
0
 

Author Comment

by:DelphiCurious
ID: 11927753
it works but it searches the first column and i want to search the third
0
 
LVL 22

Accepted Solution

by:
mnasman earned 400 total points
ID: 11928776
Hello

  I used FirstName field, you need to change it to any field you like
for example
dv.RowFilter = "FirstName '" ..
if would like to use LastName instead just change it
dv.RowFilter = "LastName '"..
0
 
LVL 2

Expert Comment

by:chrisryhal
ID: 13135155
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.

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21284699.html
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now