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

WinForms RadGridView - Deselecting all rows when user clicks on empty area

3 Answers 143 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Paolo Ascari
Top achievements
Rank 1
Paolo Ascari asked on 19 Mar 2012, 03:32 AM
Hi,

What's the best approach to deselect all rows of a WinForms RadGridView when the user clicks on the empty (i.e. blank) area of the containing grid?

(Using RadGridView Q1 2012)

Thanks in advance,
Paolo

3 Answers, 1 is accepted

Sort by
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 19 Mar 2012, 11:20 AM
Hello,

This should work for you.
this.radGridView1.MouseClick += new MouseEventHandler(radGridView1_MouseClick);

void radGridView1_MouseClick(object sender, MouseEventArgs e)
{
    if (this.radGridView1.ElementTree.GetElementAtPoint(e.Location).GetType() == typeof(GridTableElement))
    {
        this.radGridView1.ClearSelection();
        this.radGridView1.CurrentRow = null;
    }
}

Hope that helps
Richard





0
Paolo Ascari
Top achievements
Rank 1
answered on 20 Mar 2012, 12:38 AM
Hi Richard, works a treat!

I've changed it to use MouseDown instead of MouseClick.
One difference is that, for example, a click-and-drag on a scrollbar releasing the button on the empty area would also trigger a deselection, which is unintended in this case. This is because the mouse Location for the MouseClick event is determined at the 'mouse up'.

Thanks a lot for your help,
Paolo
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 20 Mar 2012, 10:20 AM
Hi Paolo,

Great. Glad it helped. Please remember to mark as answer to others can find the solution too. All the best
Richard
Tags
GridView
Asked by
Paolo Ascari
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Paolo Ascari
Top achievements
Rank 1
Share this question
or