I am using the xamDataGrid and have different sorting requirements. I have a checkbox that when checked will use the default sorting functionality provided by Infragistics (ascending, descending, null). When not checked I am applying my own sorting behind the scenes and bind that data to the grid. When doing this I need the sort indicator to show in the column header.
I have seen the post http://community.infragistics.com/forums/p/23815/87197.aspx#87197 that describes creating a new style in the xaml. This turned on the sort indicator for all column all the time.
I'm hooking into the "Sorted" event on the grid which passes "SortedEventArgs" as the parameter. This is where I am trying to apply the logic for using Infragistics sort or my custom sort. From the code behind file I need to be able to turn on and off the sort indicator visibility for a specific column. While doing this I also need to turn off and on the built in sorting (ascending, descending, null) functionality. Any help into what properties control this would be greatly appreciated.
Thanks for the quick answer Stefan
This link had the answer i was looking for
http://ko.infragistics.com/community/forums/t/29668.aspx
Shahin Rawther
This is the only way that I am aware of as well. I also think that this is somehow "crazy" just to get to the SortIndicator of the LabelPresenter. I have submitted a feature request for this - Expose the SortIndicator object publicly. I encourage you to do the same on the link below in order to raise the priority of this feature reuqest.
http://devcenter.infragistics.com/Protected/RequestFeature.aspx
Thanks
I came up with a solution although it seems like a whole lot of effort to set an arrow. First you need to get the LabelPresenter of the grid. In the callback method when you find the correct LabelPresenter you need to search through its descendants for the SortIndicator and finally set its visibility and direction properties. I really hope this saves someone in the future a good bit of headache.
private int _columnToSort;
private void myGrid_Sorted(object sender, SortedEventArgs e){ _columnToSort = e.Field.ActualPosition.Column; Infragistics.Windows.Utilities.GetDescendantFromType<LabelPresenter>(myGrid, false, new Infragistics.Windows.Utilities.DependencyObjectSearchCallback<LabelPresenter>(DescendentCallback));}
public bool DescendentCallback(LabelPresenter target){ if (target.Field.ActualPosition.Column == _columnToSort) { SortIndicator s = Infragistics.Windows.Utilities.GetDescendantFromType(target, typeof(SortIndicator), false) as SortIndicator; if (s != null) { s.Visibility = Visibility.Visible;
//logic to set the sort direction here!!! s.SortStatus = SortStatus.Ascending; }
return true; }
return false;}
The code:
SortIndicator s = Infragistics.Windows.Utilities.GetDescendantFromType(xamDataGrid1 as DependencyObject,typeof(SortIndicator),false) as SortIndicator;
has the desired affect. Unfortunately it always finds sort indicator for the first column in the grid. I've tried getting to a specific column's indicator with the following code with no luck:
private void MyGrid_Sorted(object sender, SortedEventArgs e)
{
SortIndicator s = Infragistics.Windows.Utilities.GetDescendantFromType(e.SortDescription.Field as DependencyObject, typeof(SortIndicator), false) as SortIndicator;
}
Do you know how I could modify the above code to get a specific column indicator? Alternatively if there is a way to get to the specific sort indicator given the field names:
xmlns
:igDP="http://infragistics.com/DataPresenter
<
igDP:Field Name="ProductDescription" Label="Description" />
<igDP:Field Name="CustomerName" Label="Name" >
Thanks much.
Thanks much for the quick response. I will check this out and let you know how it goes.