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

4 posts, 1 answers
  1. Paolo Ascari
    Paolo Ascari avatar
    2 posts
    Member since:
    Jun 2008

    Posted 18 Mar 2012 Link to this post

    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

  2. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 19 Mar 2012 Link to this post

    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





  3. UI for WinForms is Visual Studio 2017 Ready
  4. Paolo Ascari
    Paolo Ascari avatar
    2 posts
    Member since:
    Jun 2008

    Posted 19 Mar 2012 Link to this post

    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
  5. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 20 Mar 2012 Link to this post

    Hi Paolo,

    Great. Glad it helped. Please remember to mark as answer to others can find the solution too. All the best
    Richard
Back to Top