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

Problems ordering a Grid with an ObservableDictionary as ItemsSource

5 Answers 123 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rocio
Top achievements
Rank 1
Rocio asked on 17 Sep 2012, 07:43 AM
Hello! I am starting to use Telerik controls, and they work really well, but I am stuck with my GridView:

<telerik:RadGridView Name="gridAlarm" AutoGenerateColumns="False" EnableRowVirtualization="True">
                        <telerik:RadGridView.Columns>
                            <telerik:GridViewDataColumn Header="PtNum" DataMemberBinding="{Binding Key}" Width="auto" UniqueName="alarmas"/>
                            <telerik:GridViewDataColumn Header="Timestamp" DataMemberBinding="{Binding Value.Timestamp}"  Width="auto" />
                            <telerik:GridViewDataColumn Header="Description" DataMemberBinding="{Binding Value.Description}"  Width="auto"/>
                            <telerik:GridViewDataColumn Header="Comment" DataMemberBinding="{Binding Value.Comment}"  Width="auto" />
                            <telerik:GridViewDataColumn Header="Point" DataMemberBinding="{Binding Value.Ptname}" Width="auto" />
                            <telerik:GridViewDataColumn Header="RTU" DataMemberBinding="{Binding Value.Rtu}"  Width="auto" />
                            <telerik:GridViewDataColumn Header="Category" DataMemberBinding="{Binding Value.Category}"  Width="auto" />
                            <telerik:GridViewDataColumn Header="Table" DataMemberBinding="{Binding Value.Dbname}"  Width="auto" />
                            <telerik:GridViewDataColumn Header="Field" DataMemberBinding="{Binding Value.Fldname}"  Width="auto" />
                        </telerik:RadGridView.Columns>                       
                    </telerik:RadGridView>

First of all, I am trying to sort it by the first column, with UniqueName="alarmas" when the user clicks in a button:
 
private void radButton1_Click(object sender, RoutedEventArgs e)
        {
            gridAlarm.SortDescriptors.Add(new SortDescriptor()
            {
                Member = "alarmas",
                SortDirection = System.ComponentModel.ListSortDirection.Ascending
            });   
        }
   
And it doesn't work, I am not sure if the Member property should be the UniqueName, or not.

My second trouble is that the itemsSource of my grid is an Observable Dictionary, and when a entry changes, it also changes in the gird ( it works fine) but the changes row goes to the last position, and I would like it to go to the first or to stay in place (ordered by the first column),
When I saw that I could not order the grid by adding a SortDescriptor, I thought about generating the same event that occurs when the user clicks in the row header of a column to order the grid by it's column value, so when the Dictionary changes, I could reorder the grid by executing this event, but I could not find anything about it.

Hope you can help me because it's very important for my project.
Thanks!

5 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 17 Sep 2012, 08:08 AM
Hello,

 Could  you please confirm that you can sort clicking on the column's header? 

All the best,
Didie
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
Rocio
Top achievements
Rank 1
answered on 17 Sep 2012, 08:23 AM
Yes, the grid gets reordered when I click on the column header.
Thanks!
0
Accepted
Dimitrina
Telerik team
answered on 17 Sep 2012, 08:25 AM
Hi,

You can then add a ColumnSortDescriptor as explained in this help article.

I hope this helps.

Kind regards,
Didie
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
Rocio
Top achievements
Rank 1
answered on 17 Sep 2012, 08:30 AM
I canĀ“t see anything on that page, it's all black, I have tried before on other computers and with firefox, IE, safari and chrome, and I wasn't able to see it, could you please paste the code here?
Thanks!
0
Rocio
Top achievements
Rank 1
answered on 17 Sep 2012, 09:48 AM
Hello! I found an example with a ColumnDescriptor, and it totally worked:

gridAlarm.SortDescriptors.Clear();
            ColumnSortDescriptor csd = new ColumnSortDescriptor()
            {
                Column = this.gridAlarm.Columns["PtNum"],
                SortDirection = ListSortDirection.Ascending
            };
            this.gridAlarm.SortDescriptors.Add(csd);
 Where PtNum is the UniqueName of my column.
Thank you very much!!
Tags
GridView
Asked by
Rocio
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Rocio
Top achievements
Rank 1
Share this question
or