Solved

Filter form based on textbox and XML datasource

Posted on 2008-06-24
13
545 Views
Last Modified: 2008-07-04
I have created a combobox on a form and a datagridview. I can select a value from the combobox and populate the datagridview based on the combobox using a filter. How can I do this for a form with tetxboxes not a datagridview and use multiple comboboxes to filter not just one. This is what I use.

Public Class frmPlayersView

    Private Sub frmPlayersView_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ds As New DataSet
        ds.ReadXml("C:\DVADGOLF\tblPlayer.xml")
        ComboBox1.DataSource = ds.Tables(0).DefaultView
        ComboBox1.ValueMember = ds.Tables(0).Columns("player").ToString
        ComboBox1.DisplayMember = ds.Tables(0).Columns("player").ToString

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ds As New DataSet
        ds.ReadXml("C:\DVADGOLF\tblPlayer.xml")
        With Me.DataGridView1 'datagrid object on the form
            .DataSource = ds.Tables(0)
        End With

        Dim dv As New DataView(ds.Tables(0))
        dv.RowFilter = "Player = '" & ComboBox1.Text & "'"
        DataGridView1.DataSource = dv

    End Sub
0
Comment
Question by:wiswalld
[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
  • 7
  • 4
13 Comments
 
LVL 13

Author Comment

by:wiswalld
ID: 21867064
I was thinking this would work. Creating a dataview from the dataset and basing the textboxes on the dataview

 Dim ds As New DataSet()
        ds.ReadXml("C:\DVADGOLF\tblCourses.xml")
        Dim bs As New BindingSource(ds, "tblCourse")
        ' set binding navigators binding source
        BindingNavigator1.BindingSource = bs
        Dim dv As New DataView(ds, "tblCourse")
        dv.RowFilter = "Course " & Me.ComboBox1.Text


        txtCourse.DataBindings.Add("Text", dv, "Course")
        txtSlope.DataBindings.Add("Text", dv, "Slope")
        txtRating.DataBindings.Add("Text", dv, "Rating")
        txtHole1Yards.DataBindings.Add("Text", dv, "Hole1Yardage")
        txtHole1Par.DataBindings.Add("Text", dv, "Hole1Par")
        txtHole1Handicap.DataBindings.Add("Text", dv, "Hole1Handicap")
        txtHole2Yards.DataBindings.Add("Text", dv, "Hole2Yardage")
        txtHole2Par.DataBindings.Add("Text", dv, "Hole2Par")
        txtHole2Handicap.DataBindings.Add("Text", dv, "Hole2Handicap")



But I get an error on this line

Dim dv As New DataView(ds, "tblCourse")
0
 
LVL 18

Expert Comment

by:vbturbo
ID: 21867631
0
 
LVL 18

Expert Comment

by:vbturbo
ID: 21867782
and for implementing the BindingNavigator

http://msdn.microsoft.com/en-us/library/s4b01sz7.aspx


0
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.

 
LVL 13

Author Comment

by:wiswalld
ID: 21868164
Forget the first code I posted it is from the wrong form. I am just trying to figure out how to use this feature. The current code for the form is below. I already having a binding navigator but I am not sure about the currency manager.

Public Class frmCourses

    Private Sub txtHole1Yards_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtHole1Yards.TextChanged

    End Sub

    Private Sub TextBox11_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtHole4Par.TextChanged

    End Sub

    Private Sub frmCourses_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ds As New DataSet()
        ds.ReadXml("C:\DVADGOLF\tblCourses.xml")
        Dim bs As New BindingSource(ds, "tblCourse")
        ' set binding navigators binding source
        BindingNavigator1.BindingSource = bs

        ' bind textbox1 to this binding source, to field Player
        txtCourse.DataBindings.Add("Text", bs, "Course")
        txtSlope.DataBindings.Add("Text", bs, "Slope")
        txtRating.DataBindings.Add("Text", bs, "Rating")
        txtHole1Yards.DataBindings.Add("Text", bs, "Hole1Yardage")
        txtHole1Par.DataBindings.Add("Text", bs, "Hole1Par")
        txtHole1Handicap.DataBindings.Add("Text", bs, "Hole1Handicap")
        txtHole2Yards.DataBindings.Add("Text", bs, "Hole2Yardage")
        txtHole2Par.DataBindings.Add("Text", bs, "Hole2Par")
        txtHole2Handicap.DataBindings.Add("Text", bs, "Hole2Handicap")


        Dim dv As New DataSet
        dv.ReadXml("C:\DVADGOLF\tblCourses.xml")
        ComboBox1.DataSource = dv.Tables(0).DefaultView
        ComboBox1.ValueMember = dv.Tables(0).Columns("Course").ToString
        ComboBox1.DisplayMember = dv.Tables(0).Columns("Course").ToString




    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim path As String = "C:\DVADGOLF\tblCourses.xml"

        Dim ds As New DataSet()
        ds.ReadXml(path)
        Dim row As DataRow = ds.Tables(0).NewRow()

        'Update a value:
        row.Item(0) = Me.txtCourse.Text
        row.Item(1) = Me.txtSlope.Text
        row.Item(2) = Me.txtRating.Text
        row.Item(3) = Me.txtHole1Yards.Text
        row.Item(4) = Me.txtHole1Par.Text
        row.Item(5) = Me.txtHole1Handicap.Text
        row.Item(6) = Me.txtHole2Yards.Text
        row.Item(7) = Me.txtHole2Par.Text
        row.Item(8) = Me.txtHole2Handicap.Text


        ds.Tables(0).Rows.Add(row)    '< add the row to the table

        'Write it back out again:
        ds.WriteXml(path, XmlWriteMode.WriteSchema)

        ds.Dispose()

    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    End Sub
End Class

0
 
LVL 13

Author Comment

by:wiswalld
ID: 21868174
What I want is in button click 2 to run the code to filter the results in the dataset from the combobox that is populated in the form load event.
0
 
LVL 13

Author Comment

by:wiswalld
ID: 21868229
Sounds like the currency manager is just a navigator. I really need to searcha node or filter a node from an xml document and show its results in the form textboxes. I can populate the form textboxes using:

 Dim ds As New DataSet()
        ds.ReadXml("C:\DVADGOLF\tblCourses.xml")
        Dim bs As New BindingSource(ds, "tblCourse")
        ' set binding navigators binding source
        BindingNavigator1.BindingSource = bs

        ' bind textbox1 to this binding source, to field Player
        txtCourse.DataBindings.Add("Text", bs, "Course")
        txtSlope.DataBindings.Add("Text", bs, "Slope")
        txtRating.DataBindings.Add("Text", bs, "Rating")
        txtHole1Yards.DataBindings.Add("Text", bs, "Hole1Yardage")
        txtHole1Par.DataBindings.Add("Text", bs, "Hole1Par")
        txtHole1Handicap.DataBindings.Add("Text", bs, "Hole1Handicap")
        txtHole2Yards.DataBindings.Add("Text", bs, "Hole2Yardage")
        txtHole2Par.DataBindings.Add("Text", bs, "Hole2Par")
        txtHole2Handicap.DataBindings.Add("Text", bs, "Hole2Handicap")

Which also gives me the option to navigate.

I want to now filter these results. I was thinking of something like creating a dataview from the dataset as from my research you can use rowfilter on a dataview. Then repopulate the form textboxes on the dataview.

That was why I added this:

Dim dv As New DataView(ds, "tblCourse")
        dv.RowFilter = "Course " & Me.ComboBox1.Text


Then populate the textboxes from the dataview. I think what I need to do is clear the dataset and populate the textboxes based on the dataview like this:

 txtCourse.DataBindings.Add("Text", dv, "Course")
        txtSlope.DataBindings.Add("Text", dv, "Slope")
        txtRating.DataBindings.Add("Text", dv, "Rating")
        txtHole1Yards.DataBindings.Add("Text", dv, "Hole1Yardage")
        txtHole1Par.DataBindings.Add("Text", dv, "Hole1Par")
        txtHole1Handicap.DataBindings.Add("Text", dv, "Hole1Handicap")
        txtHole2Yards.DataBindings.Add("Text", dv, "Hole2Yardage")
        txtHole2Par.DataBindings.Add("Text", dv, "Hole2Par")
        txtHole2Handicap.DataBindings.Add("Text", dv, "Hole2Handicap")

Of course I could be way off here.
0
 
LVL 18

Expert Comment

by:vbturbo
ID: 21868695
why not just use a dataview

 
       Dim dv As DataView = ds.Tables("tblCourse").DefaultView

        txtCourse.DataBindings.Add("Text", dv, "Course")
        txtSlope.DataBindings.Add("Text", dv, "Slope")
        txtRating.DataBindings.Add("Text", dv, "Rating")
        txtHole1Yards.DataBindings.Add("Text", dv, "Hole1Yardage")
        txtHole1Par.DataBindings.Add("Text", dv, "Hole1Par")
        txtHole1Handicap.DataBindings.Add("Text", dv, "Hole1Handicap")
        txtHole2Yards.DataBindings.Add("Text", dv, "Hole2Yardage")
        txtHole2Par.DataBindings.Add("Text", dv, "Hole2Par")
        txtHole2Handicap.DataBindings.Add("Text", dv, "Hole2Handicap")


dv.RowFilter = " thisyear LIKE '%" + txtsearch.Text + "%' "
dv.Sort = "thisyear"

so every time the filter criteria in the dataview change the txtboxbindings should reflect on that
0
 
LVL 13

Author Comment

by:wiswalld
ID: 21874169
Thats what I did and added

Dim dv As New DataView(ds, "tblCourse")
        dv.RowFilter = "Course " & Me.ComboBox1.Text
 txtCourse.DataBindings.Add("Text", dv, "Course")
        txtSlope.DataBindings.Add("Text", dv, "Slope")
        txtRating.DataBindings.Add("Text", dv, "Rating")
        txtHole1Yards.DataBindings.Add("Text", dv, "Hole1Yardage")
        txtHole1Par.DataBindings.Add("Text", dv, "Hole1Par")
        txtHole1Handicap.DataBindings.Add("Text", dv, "Hole1Handicap")
        txtHole2Yards.DataBindings.Add("Text", dv, "Hole2Yardage")
        txtHole2Par.DataBindings.Add("Text", dv, "Hole2Par")
        txtHole2Handicap.DataBindings.Add("Text", dv, "Hole2Handicap")

0
 
LVL 13

Accepted Solution

by:
wiswalld earned 0 total points
ID: 21908093
I figured this out

Dim ds As New DataSet()
        ds.ReadXml("C:\DVADGOLF\tblCourses.xml")
        Dim bs As New BindingSource(ds, "tblCourse")
        ' set binding navigators binding source
        BindingNavigator1.BindingSource = bs
        Dim dv As New DataView(ds.Tables(0))
        dv.RowFilter = "Course = '" & ComboBox10.Text & "' And Tees = '" & ComboBox11.Text & "'"
0
 
LVL 18

Expert Comment

by:vbturbo
ID: 21909603
Hi

I believe that the solution talked about using a RowFilter with a DataView to filter the data,is like this:
and this is called filtering with multiple parameters.

Dim dv As New DataView(ds.Tables(0))
dv.RowFilter = String.Format("LastName = '{0}' And FirstName = '{1}' ", lastName.Text, ComboBox10.Text)

Well i got a bit confused with all your code with changing bindings. etc....

Just glad you found a solution
0
 
LVL 13

Author Comment

by:wiswalld
ID: 21909622
Thanks!
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

737 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