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

Bind Grid Datatable using Boolean Converter

1 Answer 348 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jayesh Valla
Top achievements
Rank 1
Jayesh Valla asked on 04 May 2011, 12:23 PM
Hi,

I seem to have a small problem when data binding a RadGridView Control with a Data Table via a Boolean Converter. The scenario is as follows .... I have  a DataTable of which one of the columns is of type Boolean. I would like to convert the True value to YES and False to NO. When I bind the DataColumn of the grid via a Converter class, no value is displayed. However, when I click on the filter icon of the column I can filter by YES and NO. I have gone through the forums and documentation and applied the solutions to similar problems with no success.

Converter Class
    [ValueConversion(typeof(Boolean), typeof(String))]
   class IsWhiteAreaConverter : IValueConverter
   {
       public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
       {
           return (bool)value ? "Yes" : "No";
       }
 
       public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
       {
           if ((string)value == "Yes")
           {
               return true;
           }
           else
           {
               return false;
           }
       }
   }

XAML
  <Grid.Resources>
            <my:IsWhiteAreaConverter x:Key="isWhiteAreaConverter" />
        </Grid.Resources>
 
 
 
 <telerik:RadGridView Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" Name="rgvPlan" ItemsSource="{Binding}" AutoGenerateColumns="False">

      <telerik:GridViewDataColumn Header="HalfLevel" DataMemberBinding="{Binding HalfLevelName}" />
<telerik:GridViewDataColumn Header="Is White Area" DataMemberBinding="{Binding IsWhiteArea, Converter={StaticResource isWhiteAreaConverter}}">
      <telerik:GridViewDataColumn.CellTemplate>
             <DataTemplate>
                      <TextBlock Text="{Binding IsWhiteArea, Converter={StaticResource isWhiteAreaConverter}, Mode=Default}" Foreground="AliceBlue" />
             </DataTemplate>
      </telerik:GridViewDataColumn.CellTemplate>
      <telerik:GridViewDataColumn.CellEditTemplate>
              <DataTemplate>
                     <TextBox Text="{Binding IsWhiteArea, Converter={StaticResource isWhiteAreaConverter}}" />
              </DataTemplate>
      </telerik:GridViewDataColumn.CellEditTemplate>
</telerik:GridViewDataColumn>

1 Answer, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 09 May 2011, 06:45 AM
Hi Jayesh Valla,

I have answered the support ticket you have sent. In order to keep a fruitful and consistent dialogue, use the support ticket system for any further inquiries on this topic, please.

All the best,
Ivan Ivanov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Jayesh Valla
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Share this question
or