Changing database tables displayed in a GridView control

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bagrigsb
    New Member
    • Aug 2010
    • 4

    #1

    Changing database tables displayed in a GridView control

    My project is fairly simple, since I am a relative noobie
    to VB.NET. Using a Windows Form with a Menu bar and a
    Gridview control, I have bound data to the GridView from
    an MS Access 2000 database query using Dataset.
    The contents of this table displays just fine.
    But I want to be able for the user to select a different
    query from the menu bar and display it in the same
    GridView control. How can I change the query bound to
    the control (in VB)?

    Code:
    Public Class Actinide
        Private Sub Minerals_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.Actinide_Series__Radioactive_TableAdapter.Fill(Me.Minerals2000DataSet._Actinide_Series__Radioactive_)
        End Sub
        Private Sub LanthanideToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LanthanideToolStripMenuItem.Click
             Me.Actinide_Series__Radioactive_TableAdapter.Fill(Me.Minerals2000DataSet.Lanthanide_Series)
        End Sub
        Private Sub YttriumToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles YttriumToolStripMenuItem.Click
            Me.Actinide_Series__Radioactive_TableAdapter.Fill(Me.Minerals2000DataSet.Yttrium_Minerals)
        End Sub
    End Class
    The error message that it is giving me is:
    "Value of type 'Mineralogy.Min erals2000DataSe t.Yttrium_Miner alsData Table cannot be converted to
    'Mineralogy.Min erals2000DataSe t._Actinide_Ser ies__Radioactiv e_Data Table'.

    The query is getting information from two seperate tables,
    so I can't just bind a table to the control and then
    filter what is displayed using SQL. Please Help!
    Last edited by Niheel; Sep 17 '10, 02:07 AM.
  • TamusJRoyce
    New Member
    • Apr 2008
    • 108

    #2
    Don't fill the same table twice. Make two separate DataTables. Then with the DataGridView? set dgv.DataSource = Table1, then when desired set dgv.DataSource = Table2.

    I've had times where you also had to do dgv.Refresh(), but I don't think that is necessary here.

    Please reply back if I have misinterpreted your question.

    Comment

    Working...