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

RadGridView: Loop over RowInfo: Set Row.IsVisible

4 Answers 220 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Richard Slade
Top achievements
Rank 2
Richard Slade asked on 12 Nov 2010, 05:45 PM
Hello,

I just wanted to share this in case anyone else had the same issue.

Scenario
+ RadGridView bound to datasource.
+ Multiselect enabled

Pre Q3 2010 you were able to loop over the rows and set each SelectedRow IsVisible property to False as below
Private Sub RadButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadButton1.Click
    Try
        Me.Cursor = Cursors.WaitCursor
        For Each row As GridViewRowInfo In Me.RadGridView1.SelectedRows
            row.IsVisible = False
        Next
    Finally
        Me.Cursor = Cursors.Default
    End Try
End Sub

Post Q3, you can only do this if you have only 1 row selected. With multiple rows selected the RadGridView throws an InvalidOperationException (collection was modified) exception.

In order to get over this, one needs to use the BeginUpdate / EndUpdate methods of RadGridView.

The modified code is below:

Private Sub RadButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadButton1.Click
    Try
        Me.Cursor = Cursors.WaitCursor
        Me.RadGridView1.BeginUpdate()
 
        For Each row As GridViewRowInfo In Me.RadGridView1.SelectedRows
            row.IsVisible = False
        Next
        Me.RadGridView1.EndUpdate(True)
    Finally
        Me.Cursor = Cursors.Default
    End Try
End Sub


hope someone finds this useful.

Richard

EDIT: Changed the BeginUpdate and EndUpdate to outside of the loop

4 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 12 Nov 2010, 11:14 PM
Hello Richard,

You could also use the new DeferRefresh() function, like so:
void button_Click(object sender, EventArgs e)
{
    using (radGridView1.DeferRefresh())
    {
        this.Cursor = Cursors.WaitCursor;
            
        foreach (var row in radGridView1.Rows)
        {
            row.IsVisible = false;
        }
 
        this.Cursor = Cursors.Default;
    }
}

Best Regards,
Emanuel Varga

Telerik WinForms MVP
0
Richard Slade
Top achievements
Rank 2
answered on 12 Nov 2010, 11:52 PM
Thanks for sharing, Emanuel.

I'd be interested in hearing from Telerik staff about the differences in the use of these two under this circumstance, which is more efficient etc..

All the best
Richard
0
Richard Slade
Top achievements
Rank 2
answered on 15 Nov 2010, 06:02 PM
Hi Emanuel, 

I just saw this reply from Telerik for something else and thought I would post it here too in case you (or anyone else) was interested in DeferRefresh() Vs BeginUpdate / EndUpdate()

The DeferRefresh method was included for the collections that can suspend/resume update notifications.
The DeferRefresh is also added to RadGridView and GridViewTemplate.
The logic of the DeferRefresh method is the same as the logic of BeginUpdate/EndUpdate called internally
in DeferRefresh.
This method was added to help you to achieve elegant code where you need to execute a
batch update operation.

All the best
Richard
0
Accepted
Stefan
Telerik team
answered on 17 Nov 2010, 05:06 PM
Hi guys, 

Thank you for writing.

There is no difference between the DeferRefresh and BeginEdit/EndEdit. As you can see from text posted by Richard, it is just more comfortable and elegant way of doing the same operation.

Regards,
Stefan
the Telerik team
See What's New in RadControls for WinForms in Q3 2010 on Wednesday, November 17, 11am Eastern Time: Register here>>
Tags
GridView
Asked by
Richard Slade
Top achievements
Rank 2
Answers by
Emanuel Varga
Top achievements
Rank 1
Richard Slade
Top achievements
Rank 2
Stefan
Telerik team
Share this question
or