This is a migrated thread and some comments may be shown as answers.

Header filter shows wrong values

7 Answers 21 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ernesto
Top achievements
Rank 1
Ernesto asked on 09 Oct 2013, 03:31 PM
Hello,
I have the following column to show a dropdown list to users with options "Yes", "No" or "N/A" and it is bound to a bool? property using a converter class that transforms the literals to true or false and for null values "N/A".

Here is the column definition:

<telerik:GridViewComboBoxColumn x:Name="BoolCol"

Width="165"

UniqueName="BoolCol"

DataMemberBinding="{Binding BoolCol, Mode=TwoWay, Converter={StaticResource BooleanToStringConverter}}"

DisplayMemberPath="Key"

SelectedValueMemberPath="Value"

Header="Bool Col">

</telerik:GridViewComboBoxColumn>


Here is the converter class:

public class BooleanToStringConverter : IValueConverter

{

static public string[] DefaultValues = new string[] { "Yes", "No", "N/A" };

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

{

var arr = (null != parameter) ? parameter.ToString().Split(',', ';', '|', '/')

: DefaultValues;

if (arr.Length != 3) { arr = DefaultValues; }

if (value is bool)

{

return (bool)value ? arr[0] : arr[1];

}

else

{

return arr[2];

}

}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

{

var arr = (null != parameter) ? parameter.ToString().Split(',', ';', '|', '/')

: DefaultValues;

if (arr.Length != 3) { arr = DefaultValues; }

if (string.Equals((value ?? "").ToString(), arr[2], StringComparison.CurrentCultureIgnoreCase))

{

return null;

}

return string.Equals((value ?? "").ToString(), arr[0], StringComparison.CurrentCultureIgnoreCase);

}

}


The ItemsSource is set on the constructor like this:

var BoolCol = (DataGrid.Columns["BoolCol"] as GridViewComboBoxColumn);

BoolCol.DataType = typeof(System.Nullable<bool>);

BoolCol.ItemsSource = new Dictionary<string, string>() { { "Yes", "Yes"},

{ "No", "No" },

{ "N/A", "N/A"}};


This works fine except that when the user tries to filter by clicking on the column header... the resulting list shows 3 options as expected but instead of showing the values "Yes", "No" or "N/A" it only shows "N/A" an all 3 options.
It is even more puzzling that when you check on any of the options (which all read "N/A") it correctly filters by the right option.... The first one on the array is "Yes" so if you check for the first one it will filter the data for all the true values even if the dropdown on the filter reads "N/A".

Any advices??

Thanks

7 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 10 Oct 2013, 10:40 AM
Hi,

Filtering is a data operation. Extrating the distinct values from the source collection is also a data operation. Data operations are performed over the actual raw data with LINQ queries. IValueConverters and DataStringFormats are UI stuff and they play absolutely no part in the data operations. Presentation and data are two separate things.

You can learn more about what filtering is and how it is performed by those articles:

Basic Filtering
Programmatic Filtering
Column Filtering

If your collection does not contain all distinct values that you want to diplsay you can alter the distinct values by attaching to the DistinctValuesLoading event of the grid which is also described in the documentation.

I hope this helps.

Regards,
Rossen Hristov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Ernesto
Top achievements
Rank 1
answered on 10 Oct 2013, 02:21 PM
Thanks Rossen, I understand your explanation and seems very logical... but I am passing the right values and I find not explanation of why the unique values list shown on the filter dropdown are all "N\A" and when you click on any of them the filter is applied for the right value (true or false) .
This seems to me like a bug on the Telerik side
0
Rossen Hristov
Telerik team
answered on 11 Oct 2013, 04:44 AM
Hello,

You have set your column's DataType to be Nullable<bool>, right? Yet you feed the combo box with strings only:

BoolCol.ItemsSource = new Dictionary<string, string>() { { "Yes", "Yes"},

{ "No", "No" },

{ "N/A", "N/A"}};

There are no bools in your combo box. So how can this combo provide a boolean value for the Binding. It can't. Hence your IValueConverter does nothing and always defaults to the third choice You can debug it to see.

Please respect .NET types -- Nullable<bool> and string are different types. Make sure you have set up your combo correctly by following the documentation.

Regards,

Rossen Hristov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Ernesto
Top achievements
Rank 1
answered on 11 Oct 2013, 03:15 PM
Hello Rossen,
Thanks for your answer... it is a good point that you bring on except that the filtering DOES WORK... it will be nice if you copy and paste the code I posted to see the real issue... the filtering works but the dropdown does not show the proper values... you check any of the options and the filter is applied for the right value.

Being a bit more clear:
Option on the Drop Down                     Item on the Array                 Output because of the Converter         Filter Applied on the Data
                "N/A"                                               "Yes"                                            true                                        All items field value is true
                "N/A"                                                "No"                                            false                                       All items field value is false
                "N/A"                                               "N/A"                                            null                                         All items field value is null

The issue is that the option on the drop down for the column filter should be like the item on the Array and it does not.

Sorry if I am being a bit stubborn here... really I just want an explanation and solve the issue.. the only thing that I see not working is the dropdown showing wrong values and
I have tried also setting the array with bool? 

Thanks
0
Rossen Hristov
Telerik team
answered on 14 Oct 2013, 06:41 AM
Hi,

Please, open a new support ticket and attach a runnable dummy sample project which demonstrates the issues that you are having. I will debug it and see what is going on.

Thank you.

Regards,
Rossen Hristov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Nguyễn
Top achievements
Rank 1
answered on 28 May 2014, 08:54 AM
I met the same thing. :(
0
Boris
Telerik team
answered on 31 May 2014, 02:44 PM
Hello Nguyễn,

In order to understand your scenario better, could you please send us a small isolated project that demonstrates the issue? 


Regards,
Boris Penev
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
Ernesto
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Ernesto
Top achievements
Rank 1
Nguyễn
Top achievements
Rank 1
Boris
Telerik team
Share this question
or