Hi everyone.
We've recently moved to SL5 and the latest version of SL controls (2012.3.1017.1050). We were totally surprised some of our code fails to work properly. One of the issues is about grid view selection. I prepared a little demo code which illustrates it. We have a grid:
In view model there is a property DummyObjects which is ObservableCollection<DummyObject>. Property is populated in the constructor with 10 objects with ids ranging from 1 to 10.
DummyObject class:
At the end of the view model constructor I have the following:
SelectedItem is a view model property as well.
I expected selection of the second row which actually worked in SL4, 2011 Q3. But now selection doesn't happen. Interestingly, grid's SelectedItem and SelectedItems are populated with my object but checkbox is not checked.
Making selected item be one of items in source collection does the selection:
So my question: did something changed in SL5 or gridview behavior causing not working custom equality comparison for selected items? It seems like now it's ignored, only reference comparison is performed.
I made the same research with SL Toolkit datagrid and selection works.
We've recently moved to SL5 and the latest version of SL controls (2012.3.1017.1050). We were totally surprised some of our code fails to work properly. One of the issues is about grid view selection. I prepared a little demo code which illustrates it. We have a grid:
<
telerik:RadGridView
AutoGenerateColumns
=
"false"
ItemsSource
=
"{Binding DummyObjects}"
Width
=
"600"
IsSynchronizedWithCurrentItem
=
"false"
SelectedItem
=
"{Binding SelectedItem, Mode=TwoWay}"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewSelectColumn
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Id}"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Name}"
/>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
In view model there is a property DummyObjects which is ObservableCollection<DummyObject>. Property is populated in the constructor with 10 objects with ids ranging from 1 to 10.
DummyObject class:
public
class
DummyObject
{
public
int
Id {
get
;
set
; }
public
string
Name {
get
;
set
; }
public
string
Description {
get
;
set
; }
protected
bool
Equals(DummyObject other)
{
return
Id == other.Id;
}
public
override
bool
Equals(
object
obj)
{
if
(ReferenceEquals(
null
, obj))
return
false
;
if
(ReferenceEquals(
this
, obj))
return
true
;
if
(obj.GetType() !=
this
.GetType())
return
false
;
return
Equals((DummyObject) obj);
}
public
override
int
GetHashCode()
{
return
Id;
}
}
At the end of the view model constructor I have the following:
SelectedItem =
new
DummyObject() { Id = 2 };
SelectedItem is a view model property as well.
I expected selection of the second row which actually worked in SL4, 2011 Q3. But now selection doesn't happen. Interestingly, grid's SelectedItem and SelectedItems are populated with my object but checkbox is not checked.
Making selected item be one of items in source collection does the selection:
SelectedItem = DummyObjects[1];
So my question: did something changed in SL5 or gridview behavior causing not working custom equality comparison for selected items? It seems like now it's ignored, only reference comparison is performed.
I made the same research with SL Toolkit datagrid and selection works.