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

Cannot sort columns.

5 Answers 110 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David Sandor
Top achievements
Rank 1
David Sandor asked on 03 Jun 2010, 01:41 PM
Hi, I am having a wierd problem with the WPF RadGridView control 10.1.

I am binding an ObservableCollection<> of POCO's that implement INotifyPropertyChanged and that is all.  The properties of the class are all strings.  That observable collection is databound to the ItemsSource property.  The data is bound just fine, CanUserSort is true for the control and IsSortable is true on the columns. 

Is there some sort of interface that the POCO must implement in order to sort? 

Thanks,
David Sandor

5 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 03 Jun 2010, 02:05 PM
Hi,

Can you post more info about how you grid (and columns) are declared/created? Generally RadGridView can sort any IComparable property.

All the best,
Vlad
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.
0
David Sandor
Top achievements
Rank 1
answered on 03 Jun 2010, 02:10 PM
Here is the XAML for the GridView.

 <telerik:RadGridView HorizontalAlignment="Stretch" Height="800" Name="rgvItems"   
                                 CanUserDeleteRows="False" CanUserFreezeColumns="False" CanUserInsertRows="False"   
                                 CanUserReorderColumns="False" CanUserResizeColumns="True" CanUserSelect="True"  MinColumnWidth="100" ShowGroupPanel="False" 
                                 CanUserSortColumns="True" IsReadOnly="True" 
                                  AutoGenerateColumns="False"  Background="Black" ItemsSource="{Binding InventoryOnHand}" Margin="15" > 
                <telerik:RadGridView.Columns> 
                    <telerik:GridViewColumn Header="PeopleSoftID" IsSortable="True">  
                        <telerik:GridViewColumn.CellTemplate> 
                            <DataTemplate> 
                                <TextBlock Text="{Binding AlternateItemId}" /> 
                            </DataTemplate> 
                        </telerik:GridViewColumn.CellTemplate> 
                    </telerik:GridViewColumn> 
                    <telerik:GridViewColumn Header="Item ID">  
                        <telerik:GridViewColumn.CellTemplate> 
                            <DataTemplate> 
                                <TextBlock Text="{Binding ItemId}" /> 
                            </DataTemplate> 
                        </telerik:GridViewColumn.CellTemplate> 
                    </telerik:GridViewColumn> 
                    <telerik:GridViewColumn Header="Description">  
                        <telerik:GridViewColumn.CellTemplate> 
                            <DataTemplate> 
                                <TextBlock Text="{Binding ItemDescription}" /> 
                            </DataTemplate> 
                        </telerik:GridViewColumn.CellTemplate> 
                    </telerik:GridViewColumn> 
                    <telerik:GridViewColumn Header="Manufacturer">  
                        <telerik:GridViewColumn.CellTemplate> 
                            <DataTemplate> 
                                <TextBlock Text="{Binding ManufacturerId}" /> 
                            </DataTemplate> 
                        </telerik:GridViewColumn.CellTemplate> 
                    </telerik:GridViewColumn> 
                    <telerik:GridViewColumn Header="Location">  
                        <telerik:GridViewColumn.CellTemplate> 
                            <DataTemplate> 
                                <TextBlock Text="{Binding BinLocationId}" /> 
                            </DataTemplate> 
                        </telerik:GridViewColumn.CellTemplate> 
                    </telerik:GridViewColumn> 
                    <telerik:GridViewColumn Header="Serial #">  
                        <telerik:GridViewColumn.CellTemplate> 
                            <DataTemplate> 
                                <TextBlock Text="{Binding SerialNumber}" /> 
                            </DataTemplate> 
                        </telerik:GridViewColumn.CellTemplate> 
                    </telerik:GridViewColumn> 
                    <telerik:GridViewColumn Header="RFID">  
                        <telerik:GridViewColumn.CellTemplate> 
                            <DataTemplate> 
                                <TextBlock Text="{Binding RFIDTagID}" /> 
                            </DataTemplate> 
                        </telerik:GridViewColumn.CellTemplate> 
                    </telerik:GridViewColumn> 
                    <telerik:GridViewColumn Header="" > 
                        <telerik:GridViewColumn.CellTemplate> 
                            <DataTemplate> 
                                <Button Margin="5" Height="30" Content=" USE " Click="Button_Click" Tag="{Binding RFIDTagID}" /> 
                            </DataTemplate> 
                        </telerik:GridViewColumn.CellTemplate> 
                    </telerik:GridViewColumn> 
                </telerik:RadGridView.Columns> 
            </telerik:RadGridView> 

InventoryOnHand is an ObservableCollection of POCOs that implement INotifyPropertyChanged but not IComparable.  Is that the problem?

Thanks,
David Sandor
0
Accepted
Vlad
Telerik team
answered on 03 Jun 2010, 02:12 PM
Hello David,

You need to set DataMemberBinding for these columns. For example:

...
<telerik:GridViewColumn Header="Item ID" DataMemberBinding="{Binding ItemId}">   
  <telerik:GridViewColumn.CellTemplate>
      <DataTemplate>
          <TextBlock Text="{Binding ItemId}" />
      </DataTemplate>
   </telerik:GridViewColumn.CellTemplate>
</telerik:GridViewColumn>
...

Best wishes,
Vlad
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.
0
David Sandor
Top achievements
Rank 1
answered on 03 Jun 2010, 02:16 PM
Thanks Vlad.  That worked.. I just needed to also convert the column from a GridViewColumn to a GridViewDataColumn to use the DataMemberBinding property.

-DS
0
Vlad
Telerik team
answered on 03 Jun 2010, 02:19 PM
Hi David,

Sorry! I've missed that you have GridViewColumn.

Best wishes,
Vlad
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
David Sandor
Top achievements
Rank 1
Answers by
Vlad
Telerik team
David Sandor
Top achievements
Rank 1
Share this question
or