Question Problem Clearing DataViewGrid

jimctr

Well-known member
Joined
Dec 1, 2011
Messages
52
Programming Experience
Beginner
I've seen a number of people bringing up this issue on the VB.NET 2010 but none of the suggestions end up working for me.

I fill the DataGridView manually using DataGridView1.DataSource = dt

but when I want to clear the Grid to enter more data, using some combination of the following:

dt.Clear()
DataGridView1.DataSource = Nothing 'Generates an error
DataGridView1.Columns.Clear 'Generates an error
DataGridView1.Rows.Clear()
DataGridView1.DataBindings.Clear() cannot clear this list

and myriad other suggestions I have not listed here.

I'm sure there is some combination to do this successfully. Any suggestions?

Thanks
 
Here's a more detailed error report

ErrorNotValid.jpg
 
Huh? Looks like there's something really screwy here. Do you have any customised drawing events? I've never encountered any problems with this method even using it as a toggle.

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
If DataGridView1.DataSource Is DBSet.Tables(0) Then
DataGridView1.DataSource = Nothing
Else
DataGridView1.DataSource = DBSet.Tables(0)
End If
End Sub
 
I am trying this and it is coming close, but it is still yielding also screwy results. If I do this


Dim i As Integer
Dim Test As Integer = DataGridView1.Columns.Count

If Test > 0 Then


Try

For i = (DataGridView1.Columns.Count - 1) To 0 Step -1

DataGridView1.Columns.RemoveAt(i)

Next

Catch ex As Exception

End Try
End If


This is deleting ALL BUT ONE Column which I cannot get rid of. Remember I couldn't even achieve a Parse.Exact on this machine. It wasn't working

Do you think there is a difference between Visual Studio Express 2010 and Visual Studio Professional 2010? I have professional on my old machine but it is running so poorly now I don't want to try to port the code.
 
Well again, that worked perfectly for me so I'm beginning to suspect that there's something wrong with your VS installation. There are differences between Express and Professional but not that would explain this kind of problem. The controls that both share are fundamentally the same.
 
I rewrote the entire project from scratch and it now appears to be working. The initial project I created must have been corrupted in some way.

I used:

'Clear All DataTables and DataSets
ds.Tables.Clear()
dt.Clear()
DataGridView1.DataSource = Nothing
DataGridView1.Refresh()
 
Back
Top