Solved

Filter form based on textbox and XML datasource

Posted on 2008-06-24
13
539 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
Comment Utility
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
Comment Utility
0
 
LVL 18

Expert Comment

by:vbturbo
Comment Utility
and for implementing the BindingNavigator

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


0
 
LVL 13

Author Comment

by:wiswalld
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 13

Author Comment

by:wiswalld
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
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, …
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

728 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

12 Experts available now in Live!

Get 1:1 Help Now