Solved

searching through datagrid

Posted on 2004-08-28
4
155 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 22

Expert Comment

by:Mohammed Nasman
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:
Mohammed Nasman 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

705 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