Selecting only cells of one row

2 posts, 0 answers
  1. Peter
    Peter avatar
    16 posts
    Member since:
    Apr 2012

    Posted 06 Nov 2013 Link to this post

    Hi, 

    I have a GridView with 

    grid.MultiSelect = true;
    grid.SelectionMode = GridViewSelectionMode.CellSelect;

    How can I achieve a behavior where the user can only multiselect cells of one row? I tried to use the gridFehlzeitenuebersicht_SelectionChanging Event without success. I think I just need a nice hint in the right direction. Thank you in Advance. 

    I'm using C# and RadControls for WinForms V. 2013.3.1016.40. 

    Best, 

    Peter 
  2. Stefan
    Admin
    Stefan avatar
    2911 posts

    Posted 08 Nov 2013 Link to this post

    Hello Peter,

    Thank you for writing.

    The SelectionChanging event seems like the right place do achieve the desired scenario. There you can access the already selected cells (via the SelectedCells collection of RadGridView) and the cell which attempts to be selected (vie the CurrentCell property of RadGridView). Here is a small sample:
    void radGridView1_SelectionChanging(object sender, CancelEventArgs e)
    {
        if (radGridView1.SelectedCells.Count > 0)
        {
            if (radGridView1.SelectedCells[0].RowInfo != radGridView1.CurrentRow)
            {
                e.Cancel = true;
            }
        }
         
    }

    I hope this helps.

    Regards,
    Stefan
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top