Solved

searching through datagrid

Posted on 2004-08-28
4
154 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …

726 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