I have a column in my XamDataGrid that is binded to a property of type enum.
The property name is 'Validity'. The enum type is 'EValidity', and its values are: Valid_Val, Warning_Val, Invalid_Val.
I am using a converter that converts from the enum value to an image, so the column displays images instead of the enum's values.
I set the column's width to 20, and because of this small width, I set its Label to be an empty string (" ").
When I group by this column:
1. It is displayed in the GroupByArea with no text, (because I set the label of the column to be empty). Can that be changed?
2. The grouping headers display the enum's values as they are defined in code, (which is not something I would like my users to see). Can I have control over what is displayed?
I have attached my example.
Hello Hagit,
Thank you for your post!
I have been looking into it and have modified the sample application, that you have provided.
Regarding setting the label for the Group when you group by the Validity I can suggest handling the Grouped event of the XamDataGrid. In the handler of the event you can check if there is a Group and the Field, by which is grouped is the ' Validity' field, then you can get the LabelPresenter,by using our Utilities class and set the Content property of the LabelPresenter.
Regarding the grouping headers for the enums - you can get the GroupByRecordPresenter and the TextBlock, that is inside it. You can get them using the Utilities class, as for the LabelPresenter. Then you can change the Text property of the TextBlock to your desided value.
Please find the modified sample application and feel free to let me know if you have any further questions on this matter.
Thanks for your answer.
I tried following your advice for solving the second part of my problem. What I did works, but I'm not sure that I did what you meant, so if I would appreciate if you can look at it and tell me if this is the right way.
Also, I have another question regarding the grouping headers.
Every group header states the value, and then '(n items)' where n represents the number of items under that grouping.
How do I get the number of items (without doing manipulation on the TextBlock)?
I tried following your advice for solving the second part of my problem. What I did works, but I don't know if this was what you meant.
On the Xaml I added the following:
<Style TargetType="{x:Type igDP:GroupByRecordPresenter}">
<EventSetter Event="Loaded" Handler="GroupByRecordPresenter_Loaded" />
</Style>
On code behind I implemented the event:
void GroupByRecordPresenter_Loaded(object sender, RoutedEventArgs e)
{
TextBlock txtBlock = Utilities.GetDescendantFromType(sender as DependencyObject, typeof(TextBlock), false) as TextBlock;
txtBlock.Text = txtBlock.Text.Replace("NotValid_Val", "NotValid");
txtBlock.Text = txtBlock.Text.Replace("Valid_Val", "Valid");
txtBlock.Text = txtBlock.Text.Replace("Warning_Val", "Warning");
}
Is this the way to do it?
Now I have 2 other Boolean columns: IsOk & IsValid. The group headers of both are: True & False.
Instead, I would like the group header of IsOk to be 'Ok' & 'Not Ok'. And the group headers of IsValid to be 'Valid' & 'Not Valid'.
How do I do that? Is there a way to know on that event to which column they belong?
(I have attached my sample)
I have been looking into your question. In order to replace the labels in the GroupByRecordPresenter for the IsOk and IsValid fields I can suggest to check the name of the Field in the GroupByRecordPresenter Loaded event and depending on the fields name and the Description, that the GroupByRecordPresenter has to get the TextBlock and change its TextProperty.
I have modified the sample application, that you have attached with the above mentioned functionality.
Regarding the n items that you have mentioned - this is the count of the child items in one group. You can get it in the Grouped event of the XamDataGrid. For example the following code snippet get the child items in the first group: var nItems = (sender as XamDataGrid).RecordManager.Groups[0].ChildRecords.Count;
You can also get the cound of the child item on the GroupByRecordPresenter Loaded event by using the following code snippet: ((sender as GroupByRecordPresenter).Record as GroupByRecord).ChildRecords.Count;.
Please find the attached sample application and feel free to let me know if you have any further questions on this matter.
Thank you for the fast reply.
Everything seemed to work fine, but then when I tried grouping by 2 fields, 'Validity' and by 'IsOk', the group headers got mixed up.
On the group area I expected to see 'Validity' and 'IsOk'.
Instead there was an empty header and then 'Validity'. (The empty header belongs to the 'Validity' column, and the 'Validity' header belongs to the 'IsOk' column.
Please, try it on the sample you attached and tell me if this problem can be solved.
Thanks, Hagit.