Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > GridView > Preventing a row from being selected

Not answered Preventing a row from being selected

Feed from this thread
  • Mark avatar

    Posted on Feb 3, 2012 (permalink)

    Hello,

    I have a RadGridView that uses a GridViewSelectColumn to facilitate row selection.  However, under certain circumstances, I would like to prevent certain rows from being selected.  Is there any way that I can prevent rows from being selectable?

    Thanks,
    Mark

    Reply

  • Vanya Pavlova Vanya Pavlova admin's avatar

    Posted on Feb 4, 2012 (permalink)

    Hi Mark,

     

    You may subscribe to the SelectionChanging event of RadGridView and track the CanSelect property from  there. Just cancel the event if the row should not be selected.


    Greetings,
    Vanya Pavlova
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

    Reply

  • Mark avatar

    Posted on Feb 6, 2012 (permalink)

    Hi Vanya,

    Thanks for your reply.  Yes, that is one solution, but it would still present an enabled checkbox to the user.  I was looking for a way to disable the checkbox in the GridViewSelectColumn.  So, the solutionI went with was pretty simple in the end - I created a custom column as follows.  (Hopefully it might help someone else out there.)

    public class CounterSelectionColumn
        : GridViewColumn
    {
        public CounterSelectionColumn()
        {
            IsResizable = false;
            IsReorderable = false;
            Width = GridViewLength.Auto;
            MinWidth = 25;
        }
        public override bool CanFilter()
        {
            return false;
        }
        public override bool CanSort()
        {
            return false;
        }
        public override bool CanGroup()
        {
            return false;
        }
        public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem)
        {
            if (cell != null)
            {
                CheckBox checkBox = cell.Content as CheckBox 
                    ?? new CheckBox
                    {
                        IsTabStop = false,
                    };
                checkBox.SetBinding(UIElement.IsEnabledProperty,
                    new Binding("IsAvailable")
                    {
                        Source = dataItem,
                        Mode = BindingMode.OneWay
                    });
                var row = cell.ParentRow;
                if (row != null)
                {
                    checkBox.SetBinding(ToggleButton.IsCheckedProperty,
                        new Binding("IsSelected")
                        {
                            Source = row,
                            Mode = BindingMode.TwoWay
                        });
                }
                return checkBox;
            }
            return base.CreateCellElement(cell, dataItem);
        }
    }

    Thanks,
    Mark.

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > GridView > Preventing a row from being selected
Related resources for "Preventing a row from being selected"

WPF Grid Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]