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

Gridview SelectColumn IsSelected

1 Answer 46 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Neal Robben
Top achievements
Rank 1
Neal Robben asked on 06 May 2010, 08:55 PM

I currently have a gridview that is bound to a collection of objects. These objects have a property that decides whether they should be selected or not.

Now, I know it is not possible to bind a SelectColum to a property, because it is internally bound to the IsSelected row property, as I found in the following thread:
http://www.telerik.com/community/forums/silverlight/gridview/issue-with-quot-gridviewselectcolumn-quot.aspx


But now my question is this: Is it possible to bind the IsSelected property of the row, to a property on the underlying data-object for the row. (And how to do this?)

Illustration:

SelectColumn in grid -------(Bound to)-----> IsSelected property on row-object ------(Bound to)------> Property of data-object on which row is based.

I've been trying to do this today, with little or no success. Maybe someone could tell me if it's even possible?

   Kind regards,
              Neal


1 Answer, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 10 May 2010, 07:48 AM
Hello Neal Robben,

The easiest way to do that is to use the RowLoaded event to setup a binding between the IsSelected property of a row and its data item. 

void playersGrid_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
{
    var row = e.Row as GridViewRow;
  
    if (row == null)
        return;
  
    var selectedBinding = new Binding("Selected");
    selectedBinding.Source = row.Item;
    selectedBinding.Mode = BindingMode.TwoWay;
  
    row.SetBinding(GridViewRow.IsSelectedProperty, selectedBinding);
}

All the best,

Milan
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Neal Robben
Top achievements
Rank 1
Answers by
Milan
Telerik team
Share this question
or