VB NET Filtering Datagrid view with Radio buttons

I am trying to filter a datagrid view by using  radio buttons.  for example   i have 2 radio buttons    named  full time /part time status.   when i check one of them,  i want it display   the names and salary ,with that particular status  in the data grid . I know how to do by adding a query with certain parameters that display what i want but i have never done it with radio buttons before.

How do i set this up.?
Ajs135Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JoozefCommented:
I will assume you are using Winforms.

Bind your DataSource for the DataGridView to a BindingSource object and populate the grid will all of your data.  Then, in the CheckedChanged event of the Radio Buttons, set the Filter property of the BindingSource object like this:-


  bsInstance.Filter = "Status = 'FullTime'"   'Watch for the single quotes around the word FullTime


HTH,
Joe



0
Ajs135Author Commented:
k  i know  bsindtance  i replace it with my databse name object.     but the  word Filer at the end of it  what is that supposed to be a command for it?   b/c i when i try to set it     for example  the database i have is  Companydataset.xsd            

i try setting it companydataset.filer  ="Status = 'Full_Time'"  but  u keep getting error stating filter is not a member of the datasource.      One thing also.  "FullTime" refers to the name of the column or row of the datasource correct?
0
JoozefCommented:
You can't set a filter on the dataset.  The "BindingSourceObject" is bound to your DataTable in the Dataset.  Then you bind the DataGrid to the BindingSourceObject.
Like this:
     DataTable --> BindingSourceObject (name=bsInstance) --> DataGridView
  1. Bind the DataTable instance to the BindingSourceObject
  2. Bind the DataGridView to the BindingSourceObject.
  3. Populate the DataTable. (This should show all records in the DataGridView)
  4. Set the Filter property on the BindingSourceObject like this:-
         bsInstance.Filter = "Status = 'FullTime'" where "Status" refers to a column on the Datatable and 'FullTime' is the value on the rows you want displayed.  This step would be done from the "CheckChanged" event on the RadioButton control.

    The Filter property is like using a "WHERE" clause using SQL style syntax but it is done on the BindingSourceObject, not the Datatable itself.  Once the BindingSourceObject's Filter property has been set, this will automatically show the filtered results in the DataGridView.
Let me know if you need more clarification.
Joe
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Ajs135Author Commented:
Set the Filter property on the BindingSourceObject like this:-
    bsInstance.Filter = "Status = 'FullTime'" where "Status" refers to a column on the Datatable and 'FullTime' is the value on the rows you want displayed.  This step would be done from the "CheckChanged" event on the RadioButton control.


i am to get steps 1 -3 ,  but when it comes to the radio button i cant get it to work.        

i went to the radio button properties and under databindings i go to the checked event properties, and trying to set it to filter only the ons that are checked in the datagrid which are the full time. but it just keeps showing eveyrthing,.   this is still confusing
0
JoozefCommented:
Here is a basic sample of what I mean.
In Project B, I would create the Dataset using the designer and the DataProxy class to access it.
In Project A, I would instantiate the Dataset and a BindingSourceObject to bind the Dataset to the Grid.  Use the Filter property of the BindingSourceObject to filter what the Grid shows.
I have attached a working VS2008 3.5 sample.
See how you go.
Joe
 

'PROJECT B (Business Logic)

Public Class DataProxy

  Public Shared Function GetFruit() As FruitDataset

    Dim ds As New FruitDataset
    Try
      Dim ta As New FruitDatasetTableAdapters.FruitBowlTableAdapter
      Using ta
        ta.Connection = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\Fruit.mdb;Persist Security Info=True")
        ta.Fill(ds.FruitBowl)
      End Using
    Catch ex As Exception
      'Error trapping in here
    End Try
    Return ds
  End Function

  Public Shared Sub SaveFruit(ByVal ds As FruitDataset)
    Try
      Dim ta As New FruitDatasetTableAdapters.FruitBowlTableAdapter
      Using ta
        ta.Connection = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\Fruit.mdb;Persist Security Info=True")
        ta.Update(ds.FruitBowl)
      End Using
    Catch ex As Exception
      'Error trapping in here
    End Try
  End Sub

End Class


'PROJECT A (with a reference to Project B) for UI
Public Class Form1

  Private Sub opt_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optAll.CheckedChanged, _
                                                                                                     optGreen.CheckedChanged, _
                                                                                                     optYellow.CheckedChanged
    Dim opt As RadioButton = CType(sender, RadioButton)
    Dim sFilter As String = opt.Text

    Select Case sFilter.ToLower
      Case "all"
        'Clear the filter and show all records
        Me.FruitBindingSource.Filter = ""
      Case Else
        'Show all records where the colour equals the Text on the RadioButton
        Me.FruitBindingSource.Filter = String.Format("Colour = '{0}'", sFilter)
    End Select

  End Sub

  Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
    With Me.FruitDataset
      'Get the data from DataProxy class in Project B
      .Merge(ProjectB_BusinessLogic.DataProxy.GetFruit())
    End With
  End Sub

  Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
    'Lock in the changed
    Me.FruitBindingSource.EndEdit()
    'Send the changes back to the Database via the DataProxy class in Broject B
    ProjectB_BusinessLogic.DataProxy.SaveFruit(Me.FruitDataset)
  End Sub

End Class

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JoozefCommented:
The attachment didn't seem to work.  I'll try again...
Also, the colours in the code snippets above went a little crazy!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.