hi everyone
my question is how to clear a datagrid view in vb.net 2010
i have tried DatGridView1.Clear() but it only works once
and i would like to clear my datagrid every time i click the load button
hers my code

Private Sub Button15_Click(sender As System.Object, e As System.EventArgs) Handles Button15.Click

        OpenFileDialog1.Title = "Please Select a File"
        OpenFileDialog1.InitialDirectory = "C:temp"

    End Sub

Private Sub OpenFileDialog1_FileOk(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
        dgQuotation.DataSource = Nothing
        Dim strm As System.IO.Stream
        strm = OpenFileDialog1.OpenFile()
        strPath = OpenFileDialog1.FileName

        If Not (strm Is Nothing) Then
            dgQuotation.DataSource = Nothing
            ' Dim col As New DataGridViewTextBoxColumn
            'column declaration
            dgQuotation.ColumnCount = 43
            For Each line As String In System.IO.File.ReadAllLines(strPath)

        End If
    End Sub

Why not bind the datagridview to a bindingsource. the reset the bindingsource.
You will need a datatable or a collection but that should give you what you want. All you have to do is clear the datasource of the bindingsource and call the ResetBindings(False) method on the bindingsource

DataGridView1.Rows.Clear() will clear the rows for you.
If you want to completely clear everything from the grid you could then add DataGirdView1.Columns.Clear() to clear the columns as well.

This article has been dead for over six months. Start a new discussion instead.