I have a XamDataGrid in which there is a Column COUNT to which the values are assigned dynamically.
What i want is if the column cell value is 2 then convert it to hyperlink with text CLICK and if the cell value is 1 then it should remain as it is(no hyperlink, no text change).
Kind Regards
Hello Sachin,
Yes, this is also expected, as even if the DisplayText is set to “Special”, separate values such as “"Test~Case~1" and "Test~Case~2" are still treated as such. Therefore, if you have multiple entries of the former and also multiple of the latter in your data, the total appearances of “Special” in the filter dropdown would be 2. Therefore, the suggested solution assumed that there were only unique values satisfying the condition to contain “~”, as no information regarding the opposite was previously provided.
Fortunately, there are still options to workaround this. My suggestion is to use a Converter on the TemplateField, whose Convert method returns the “Special” string in case the original values contains the ‘~’ character.
internal class MyVlaueConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value.ToString().Contains('~')) { return "Special"; } else { return value; } } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } }
Please, be sure to also modify the DataTemplateSelector, so that it sets the “SpecialTemplate” incase the value is equal to “Special”, with the new logic introduced:
//.. else if (val.Equals("Special")) { dataTemplate = editor.FindResource("SpecialTemplate") as DataTemplate; }
Additionally, handling the RecordFilterDropDownOpening event is no longer needed.
Attached you will find the latest version of the sample demonstrating this suggestion. Please, test it on your side and let me know how it behaves.
Best regards,Bozhidara Pachilova
8156.XDGConditionalHyperlink3.zip
Hi Bozhidara Pachilova,
I have tried the code you have provided but it again gave an issue for my project, In my project there are more than 50 items in the dropdown list out of which approx. 30 are having special character (~) for which i wanted them to be shown as "Special" on dropdown menu.
My requirement was that if there are 30 items with special character(~) inside them they should be shown with text "Special" only SINGLE time on the dropdown list not 30 times and if I select "Special" on the dropdown list it should show all the 30 items with text "Special" on my grid.
Kind Regards,
Hi Sachin,
You could handle this by leveraging the grid’s RecordFilterDropDownOpening event, from which you can set the target item’s DisplayText to another value, for instance:
private void XamDataGrid_RecordFilterDropDownOpening(object sender, Infragistics.Windows.DataPresenter.Events.RecordFilterDropDownOpeningEventArgs e) { foreach (var item in e.DropDownItems) { if (item.DisplayText.ToString().Contains("~")) { item.DisplayText = "Special"; } } }
Best regards, Bozhidara Pachilova
Hello Bozhidara Pachilova
Thanks for your help and for your sample.
The sample you gave me worked for my condition but it raised another issue on my XamDataGrid FilterRecords Property. As i have explained that my requirement was that if i had a string with special character(~), i wanted my string to be converted to a Hyperlink with the text "Special" on it.
Now my issue is I have "AllowRecordFiltering" property applied to my Template field which is set to "True", which when i am trying to filter my record the string with (~) shows up there rather than my text Special on Filter Record dropdown.
In my FilterRecord DropDown i want Special text to appear rather than Test~Case~1.Please check attached screenshot.
I am glad that this helps!
For the sake of completeness, I am reattaching the sample again due to the previously missing selector class file.
5852.XDGConditionalHyperlink2.zip