This is a migrated thread and some comments may be shown as answers.

How can we just clear radgridview

5 Answers 292 Views
GridView
This is a migrated thread and some comments may be shown as answers.
andi
Top achievements
Rank 1
andi asked on 21 Nov 2018, 09:09 AM

Hi All,

How can we just clear radgridview, clear row, column, relation also on their template ?. Then radgridview being like the first time it loaded when then application run. So we can define columns on it over and over. Instead of using those :

        RadGridView1.DataSource = Nothing
        template.DataSource = Nothing
        template1.DataSource = Nothing

        While Me.RadGridView1.Rows.Count > 0
        Me.RadGridView1.Rows.RemoveAt(Me.RadGridView1.Rows.Count - 1)
        End While

        While Me.RadGridView1.Columns.Count > 0
            RadGridView1.Columns.RemoveAt(Me.RadGridView1.Columns.Count - 1)
        End While

        While template.Rows.Count > 0
        template.Rows.RemoveAt(template.Rows.Count - 1)
        End While

        While Me.RadGridView1.Relations.Count > 0
            Me.RadGridView1.Relations.RemoveAt(Me.RadGridView1.Relations.Count - 1)
        End While

 

Thanks in advance

5 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 22 Nov 2018, 11:15 AM
Hello, Andi, 

Setting the DataSource property to null for the respective template in RadGridView is a suitable approach for clearing the data loaded in the control. If the columns are automatically generated, setting the DataSource property to null, will also clear the columns as well. However, it would be necessary to clear the Relations/Templates collections if you have setup hierarchy. It is just necessary to call the Relations.Clear method.

I hope this information helps.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
andi
Top achievements
Rank 1
answered on 23 Nov 2018, 01:21 AM
RadGridView1.Templates.Clear() need to do on hierarchy isn't it
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 23 Nov 2018, 09:17 AM
Hello, Andi, 

The MasterTemplate.Templates.Clear method should be called in order to clear the hierarchy levels. The same is valid for the Relations collection as it is noted in my previous post.

Are you experiencing any difficulties with it?


Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
nate
Top achievements
Rank 1
answered on 28 Nov 2018, 11:18 PM

In order to remove a single row from RadGridView, you should simply call the the Removemethod and pass an object of type GridViewDataRowInfo as an argument :  this.radGridView1.Rows.Remove(rowToRemove);

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 29 Nov 2018, 09:08 AM
Hello, Nate,    

The RadGridView.Rows.Remove method allows you to remove row by row. However, this won't clear the columns, the hierarchical templates and relations. It is applicable if you just want to clear the rows.

I hope this information helps. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
andi
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
andi
Top achievements
Rank 1
nate
Top achievements
Rank 1
Share this question
or