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

Row Selection by Checkbox Column only

1 Answer 85 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Lance
Top achievements
Rank 1
Lance asked on 10 Jul 2014, 05:38 PM
I  have an unbound checkbox column that can be used to select rows in the grid. But I also need to disable the default method of selecting and highlighting the current row by clicking on it. I would only like to select and highlight the rows that have their respective checkboxes clicked.

I can't find any property that would disable row selection, so how can this be achieved?

1 Answer, 1 is accepted

Sort by
0
George
Telerik team
answered on 15 Jul 2014, 11:32 AM
Hi Lance,

Thank you for writing.

In order to have such functionality you should intercept the mouse input. You can execute custom logic if RadCheckmark is clicked. This must happen in a custom GridDataRowBehavior:
class MyRowBehavior : GridDataRowBehavior
{
    public override bool OnMouseDown(MouseEventArgs e)
    {
        RadCheckmark element = this.GridControl.ElementTree.GetElementAtPoint(e.Location) as RadCheckmark;
        if (element != null)
        {
            if (element.CheckState == ToggleState.On)
            {
                element.CheckState = ToggleState.Off;
            }
            else
            {
                element.CheckState = ToggleState.On;
            }
 
            GridCheckBoxCellElement cell = element.Parent.Parent as GridCheckBoxCellElement;
            cell.RowInfo.IsSelected = element.CheckState == ToggleState.On ? true : false;
        }
 
        return false;
    }
}

Now you can register the new behavior and configure the grid:
BaseGridBehavior baseBehavior = grid.GridBehavior as BaseGridBehavior;
baseBehavior.UnregisterBehavior(typeof(GridViewDataRowInfo));
baseBehavior.RegisterBehavior(typeof(GridViewDataRowInfo), new MyRowBehavior());
 
grid.Columns.Add(new GridViewCheckBoxColumn());
grid.Rows.AddNew();
grid.Rows.AddNew();
grid.Rows.AddNew();
grid.MultiSelect = true;
grid.CurrentRow = null;

I hope this helps.

Regards,
George
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
Lance
Top achievements
Rank 1
Answers by
George
Telerik team
Share this question
or