Results 1 to 11 of 11

Thread: DataGridView Data Source Question

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2018
    Posts
    6

    DataGridView Data Source Question

    i have a form built on a poker timer to select one of three data tables in an access database based on a radio button event
    how do i tell the radio buttons to load the requisite table based on the radio button clicked?
    tables are
    daily
    sunday
    special
    the base load is the daily

  2. #2
    Fanatic Member kpmc's Avatar
    Join Date
    Sep 2017
    Posts
    1,012

    Re: DataGridView Data Source Question

    Can you show your code that is loading the data.

    Generally speaking you would change youre connection string conditionally as per the radio button value

  3. #3
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: DataGridView Data Source Question

    Generally speaking you would change youre connection string conditionally as per the radio button value
    No you wouldn't change the connection string, it connects to the database file not individual tables. You would change the SQL command the retrieves the data.

    You could do this in the Radio Button "CheckedChanged" event.

  4. #4
    Fanatic Member kpmc's Avatar
    Join Date
    Sep 2017
    Posts
    1,012

    Re: DataGridView Data Source Question

    Quote Originally Posted by wes4dbt View Post
    No you wouldn't change the connection string, it connects to the database file not individual tables. You would change the SQL command the retrieves the data.

    You could do this in the Radio Button "CheckedChanged" event.
    That's what i meant actually. The commandtext

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2018
    Posts
    6

    Re: DataGridView Data Source Question

    the base load is done through the properties setting on the datagridview. i was wondering if there was a means to adjust that instead of the connection string use

  6. #6
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: DataGridView Data Source Question

    I've already said where to make the datagridview datasource change, are you asking how to change the dgv datasource? If so, then you need to provide more information about the datasource and post your current code. It will be a lot easier to help you if you provide a Full and Clear explanation.

  7. #7

    Thread Starter
    New Member
    Join Date
    Jan 2018
    Posts
    6

    Re: DataGridView Data Source Question

    yes wes that is exactly what i am asking. the overall dataset is comprised of three tables in a connected resource database. in the properties view of the dgv i have the datasource set as DailyBindingSource in reference to the daily table. how would i programatically tell that property to adjust to the sundaybindingsource or specialbindingsource as needed based on a radio button checked on an alternate form. code as waiting is as follows
    Private Sub RBDaily_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RBDaily.Click, RBSunday.Click, RBSpecial.Click
    Dim rad As RadioButton = CType(sender, RadioButton)
    Select Case rad.Name
    Case RBDaily.Name
    Form1.DataGridView1.DataSource =
    Case RBSunday.Name
    Form1.DataGridView1.DataSource =
    Case RBSpecial.Name
    Form1.DataGridView1.DataSource =
    End Select
    End Sub

  8. #8
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: DataGridView Data Source Question

    Well that's a start, so your saying the Radio buttons and the Datagridview are on different forms?
    Which form is this code on,
    Code:
    Private Sub RBDaily_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RBDaily.Click, RBSunday.Click, RBSpecial.Click
    Dim rad As RadioButton = CType(sender, RadioButton)
    Select Case rad.Name
    Case RBDaily.Name
    Form1.DataGridView1.DataSource =
    Case RBSunday.Name
    Form1.DataGridView1.DataSource =
    Case RBSpecial.Name
    Form1.DataGridView1.DataSource = 
    End Select
    End Sub
    Are all the bindingsources in the same form as the dgv?

    I still think you should be using the Radiobutton CheckedChanged event, like
    Code:
        Private Sub RBSunday_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
            If RBSunday.Checked Then
                Form1.DataGridView1.DataSource = "yourdatasource"
            End If
        End Sub

  9. #9

    Thread Starter
    New Member
    Join Date
    Jan 2018
    Posts
    6

    Re: DataGridView Data Source Question

    that code is on formdataset
    all binding sources are on form1 with the dgv
    my question is more how do i reference the datasource to complete the line?

  10. #10
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: DataGridView Data Source Question

    Code:
        Private Sub RBSunday_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
            If RBSunday.Checked Then
                Form1.DataGridView1.DataSource = Form1.sundaybindingsource
            End If
        End Sub
    That would be my guess but I can't be positive because I never use Default Form Instances like your doing. I don't like coding like that.

  11. #11

    Thread Starter
    New Member
    Join Date
    Jan 2018
    Posts
    6

    Re: DataGridView Data Source Question

    perfect thank you sir

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width