This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hello Mindscape team, the IsGroupingPanelVisible="True" in Datagrid is nice. I wander if there is an option to have a CustomGrouping condition for each column I can group. 1. Easily explained what I want to achieve is to group a Amount-column by 0-100€,100.01€ - 500€,500€ - inf. which results in three groups. Currently I get many more groups whenever the value differs. Further I have another column "Purpose". This column contains string, I would like to group them by a SimilarityMeasure. If values i.e. 80% similar then they belong to a group. These two grouping for sure need to work nested as well :) 2. Besides, a further question and trivial in comparison regarding sortcomparer: - if I implement a IComparer (public int Compare(object x, object y)) I always the bound viewmodel in x and y. Is there a chance to get the bound property directly instead as reference? Thanks in advance, Maik |
|
|
Hello Maik 1) There is one way you can provide custom grouping logic at the moment. You can use the DataGridColumn.DisplayMemberBinding property to bind to the Amount property and provide a converter that has the grouping logic. Then you'll need to manually specify the display template and editor template for this column so that the display is not affected by this converter. So on the Amount column, you would set the DisplayMemberBinding property something like this:
In the AmountConverter, you would return a value that indicated which group the value belongs to. You could return the first value of the group range such as, 0, 100, and 500. You may also want to provide a GroupRowHeaderTemplate to customize the appearance of the group header. You'd want this to display the value range such as "0-100€". Next set the DisplayTemplate and EditorTemplate properties of the column. The editor template could be something like this:
The Text property of the TextBox is binding directly to the Amount property on your model objects. Alternatively, you could use one of our numeric controls. Then for the display template, you do a similar thing, but simply bind the Text of a TextBlock element. Now the cell display is not affected by the AmountConverter. Then use a similar approach for your Purpose column. Note that setting the DisplayMemeberBinding also affects the sorting. So you may need to provide a sort comparitor to work around this. If this overall approach is not going to work for you, for example you are already using the DisplayMemberBinding, then let me know and I'll find another way to provide custom grouping logic. 2) I'm not entirely sure what you want here, could you please give another example? Cheers Jason Fauchelle |
|
|
Hello Jason, thank you for your quick reply. Your answer to (1) worked fone for me. Regarding my question 2: As far as I understood to have custom sort, I define it in XAML Like this
...
Therefore, I create a class like and implement the interface like this:
The references/values given in x and y are always the viewmodel, where the whole datagrid-item is bound to. Is there a chance to know which column is affected? I would like to do something like this
Bye Maik |
|
|
Hello Maik From the sort comparer, there isn't a way to get the column it is applied to. What I would recommend is to put a property on your ByNameComparer class to indicate which property you want to apply the sorting to. Then in xaml, you can create one instance of the ByNameComparer for each column you want to use it on. For each instance, set the property I mentioned based on the column you are going to give it to. In the compare method, you can use this property to determine which value to sort the column by. Jason Fauchelle |
|