|
-
Oct 14th, 2008, 11:54 AM
#1
Thread Starter
Frenzied Member
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! 
-
Oct 14th, 2008, 12:01 PM
#2
Re: clear datagrid
Hi,
You can try this:
vb Code:
dataSet1.Clear() dataGrid1.DataSource = dataSet1.TableNameHere.DefaultView
Hope it helps,
sparrow1
-
Oct 14th, 2008, 12:31 PM
#3
Thread Starter
Frenzied Member
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! 
-
Oct 14th, 2008, 12:52 PM
#4
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:
Wkr,
sparrow1
-
Oct 14th, 2008, 02:56 PM
#5
Thread Starter
Frenzied Member
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! 
-
Oct 14th, 2008, 07:47 PM
#6
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|