This question is locked. New answers and comments are not allowed.
Hi,
I am using an observable collection as data source for the grid. The collection object has two types of amount fields, one decimal type and another string type. I am using string type field to display in Amount column as I like to show the negative amounts in a parenthesis instead of printing the negative sign. But when I do a sort on the Amount column (which is actually a string type) I would like to use the hidden decimal column for sorting purposes as the string sorting will give different result than the numeric. Is there any way to achieve this?
Also, if the AmountType, another field in the object, is "C" then I like to show the entire row with a different background color, is it possible? Do you have any sample code for this?
Any help is appreciated.
Thanks
I am using an observable collection as data source for the grid. The collection object has two types of amount fields, one decimal type and another string type. I am using string type field to display in Amount column as I like to show the negative amounts in a parenthesis instead of printing the negative sign. But when I do a sort on the Amount column (which is actually a string type) I would like to use the hidden decimal column for sorting purposes as the string sorting will give different result than the numeric. Is there any way to achieve this?
Also, if the AmountType, another field in the object, is "C" then I like to show the entire row with a different background color, is it possible? Do you have any sample code for this?
Any help is appreciated.
Thanks
5 Answers, 1 is accepted
0
Hi Srinivas,
In the current grid version you can cancel the grid Sorting event and add desired SortDescriptor. You can try however our latest internal build - we added new column property called SortMemberPath.
Sincerely yours,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
In the current grid version you can cancel the grid Sorting event and add desired SortDescriptor. You can try however our latest internal build - we added new column property called SortMemberPath.
Sincerely yours,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Srinivas
Top achievements
Rank 1
answered on 17 Sep 2009, 06:42 PM
Hello Vlad,
This is what I have done. In the XAML code for the string column I have added SortingStateChanged event and in the event handler method I added below code:
private void GridViewDataColumn_SortingStateChanged(object sender, RadRoutedPropertyChangedEventArgs<SortingState> e)
{
foreach (SortDescriptor sd in this.InvoiceGrid.SortDescriptors)
{
//remove string amount column from the sort
if (sd.Member == "InvoiceAmountStr")
this.InvoiceGrid.SortDescriptors.Remove(sd);
}
//add decimal amount column to the sort
SortDescriptor amountSort = new SortDescriptor();
amountSort.Member = "InvoiceAmount";
//amountSort.SortDirection = ListSortDirection.Descending;
this.InvoiceGrid.SortDescriptors.Add(amountSort);
}
When I try to click on the sort icon for the column I am getting below exception:
Cannot change ObservableCollection during a CollectionChanged or PropertyChanged event.
Can you please guide me how to cancel and add new sort column?
Thanks
This is what I have done. In the XAML code for the string column I have added SortingStateChanged event and in the event handler method I added below code:
private void GridViewDataColumn_SortingStateChanged(object sender, RadRoutedPropertyChangedEventArgs<SortingState> e)
{
foreach (SortDescriptor sd in this.InvoiceGrid.SortDescriptors)
{
//remove string amount column from the sort
if (sd.Member == "InvoiceAmountStr")
this.InvoiceGrid.SortDescriptors.Remove(sd);
}
//add decimal amount column to the sort
SortDescriptor amountSort = new SortDescriptor();
amountSort.Member = "InvoiceAmount";
//amountSort.SortDirection = ListSortDirection.Descending;
this.InvoiceGrid.SortDescriptors.Add(amountSort);
}
When I try to click on the sort icon for the column I am getting below exception:
Cannot change ObservableCollection during a CollectionChanged or PropertyChanged event.
Can you please guide me how to cancel and add new sort column?
Thanks
0
Hi Srinivas,
I have prepared a sample project with our latest internal build. You can get the Latest Internal Build from your Client.Net.
Here is how to do it:
Please find the sample project attached.
Greetings,
Ross
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
I have prepared a sample project with our latest internal build. You can get the Latest Internal Build from your Client.Net.
Here is how to do it:
| <UserControl x:Class="TicketID_243551_SortMemberPath.MainPage" |
| xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
| xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
| xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
| xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" |
| mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"> |
| <Grid> |
| <telerik:RadGridView Name="grid" |
| AutoGenerateColumns="False" |
| ColumnsWidthMode="Auto"> |
| <telerik:RadGridView.Columns> |
| <telerik:GridViewDataColumn Header="StringColumn" |
| DataMemberBinding="{Binding StringColumn}" |
| SortMemberPath="IntColumn"/> |
| <telerik:GridViewDataColumn Header="IntColumn" |
| DataMemberBinding="{Binding IntColumn}"/> |
| </telerik:RadGridView.Columns> |
| </telerik:RadGridView> |
| </Grid> |
| </UserControl> |
| using System.Collections.Generic; |
| using System.Windows.Controls; |
| namespace TicketID_243551_SortMemberPath |
| { |
| public partial class MainPage : UserControl |
| { |
| public MainPage() |
| { |
| this.InitializeComponent(); |
| IList<BusinessObject> data = new List<BusinessObject>(); |
| data.Add(new BusinessObject {StringColumn = "One", IntColumn = 1}); |
| data.Add(new BusinessObject {StringColumn = "Two", IntColumn = 2}); |
| data.Add(new BusinessObject {StringColumn = "Minus One", IntColumn = -1}); |
| data.Add(new BusinessObject {StringColumn = "Minus Two", IntColumn = -2}); |
| data.Add(new BusinessObject { StringColumn = "Four", IntColumn = 4 }); |
| data.Add(new BusinessObject { StringColumn = "(5)", IntColumn = -5 }); |
| this.grid.ItemsSource = data; |
| } |
| } |
| public class BusinessObject |
| { |
| public int IntColumn { get; set; } |
| public string StringColumn { get; set; } |
| } |
| } |
Please find the sample project attached.
Greetings,
Ross
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
xiaofeng
Top achievements
Rank 1
answered on 27 Nov 2009, 01:24 AM
I use the SortMemberPath property for some columns.But when I sort these column,the Sorted event can not be executed.I do no know what happend!
0
Hello,
I've just checked this using our latest binaries however everything worked fine. You can check the attached project for reference.
Regards,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
I've just checked this using our latest binaries however everything worked fine. You can check the attached project for reference.
Regards,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
