How to bind row IsSelected of GridView

1 Answer 106 Views
GridView
lou
Top achievements
Rank 1
lou asked on 05 Dec 2022, 09:03 AM

I hava a model that contains IsSelected Property, and I want to bind the row IsSelected of gridview to that IsSelected, what should i do?

class MyClass
{
    public bool IsSelected { get; set; }
}

private BindingSource _bindingSource;
private List<MyClass> _myClassList;
private RadGridView _gridView;

private void DataBinding()
{
    _bindingSource = new BindingSource { DataSource = _myClassList };
    // how to bind _gridView.Rows.IsSelected to _myClassList.IsSelected?
    _gridView.DataSource = _bindingSource;
}

1 Answer, 1 is accepted

Sort by
1
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 05 Dec 2022, 12:30 PM

Hello, lou,     

There is not automatic way for binding a custom property from the DataBoundItem to the IsSelected property of the grid row because the selection is intended to be related with the user's mouse interaction.

If you need to achieve any custom logic, you can subscribe to the CellValueChanged, check the affected column and mark the row as selected if necessary according to the respective property from the DataBoundItem: https://docs.telerik.com/devtools/winforms/controls/gridview/selection/selecting-rows-and-cells-programmatically 
I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

lou
Top achievements
Rank 1
commented on 06 Dec 2022, 01:32 AM

Thank you for your reply, CellValueChanged works for me.
Tags
GridView
Asked by
lou
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or