Results 1 to 6 of 6

Thread: clear datagrid

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    clear datagrid

    I need to clear datagrid Tab Page on leave method.

    I have tried the following but nothing works. Any idea?



    Private Sub TbView_leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TbViewStockbalance.Leave
    DataGrid3.Refresh()

    End Sub

    Private Sub TbView_leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TbViewStockbalance.Leave
    DataGrid3.bindings.clear

    End Sub
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

  2. #2
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: clear datagrid

    Hi,

    You can try this:

    vb Code:
    1. dataSet1.Clear()
    2.    
    3.      dataGrid1.DataSource = dataSet1.TableNameHere.DefaultView

    Hope it helps,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: clear datagrid

    Nope, throws an exception;

    Object reference not set to an instance of an object.
    ----------------------------------------------------

    Code:
    Private Sub TbViewStockbalance_leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TbViewStockbalance.Leave
            Dim dataset1 As DataSet = New DataSet
            dataset1.Clear()
            DataGrid3.DataSource = dataset1.Tables("tb_transaction_log").DefaultView
        End Sub
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

  4. #4
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: clear datagrid

    Hi,

    I'm assuming you want to clear the datatable which will have the effect of
    clearing the grid? To clear the datatable you can just call:

    vb Code:
    1. DataTableName.Clear

    Wkr,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: clear datagrid

    Doesnt work sparrow1,


    Well Im populating with :

    Code:
    Using mMySqlDataAdapter As New SqlClient.SqlDataAdapter(cmd)
                        Using mDataSet As New DataSet 'call dataset
                            mDataSet.Clear()
                            mMySqlDataAdapter.Fill(mDataSet, "tb_book") 'fill dataset with the table in the query
                            mDataView = New DataView
                            mDataView.Table = mDataSet.Tables("tb_book"

    then I need to clear the grid on Tab Pag leave.
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: clear datagrid

    First up, why do you have a Using block? Why would you want to dispose a DataSet that you're binding to a control and, therefore, continuing to make use of past the End Using line?

    Secondly, why are you using a DataSet at all? Or a DataView for that matter? All you need is one DataTable. Create it, populate it, bind it, end of story.

    Finally, when you want to clear your grid then you need to clear THAT DataTable, or else set the DataSource to Nothing. There's no point creating a new DataSet or DataTable and clearing that. If your TV is on and you want to turn it off do you go out and buy a new TV and turn that off? If you did would that affect the TV you already have?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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