Solved

Filter form based on textbox and XML datasource

Posted on 2008-06-24
13
546 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
Technology Partners: 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!

 
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

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

724 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