Solved

Filter form based on textbox and XML datasource

Posted on 2008-06-24
13
541 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
  • 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

813 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

10 Experts available now in Live!

Get 1:1 Help Now