Welcome to the Xceed Community Sign in | Join | Help
Community Search  

Re: Question about checkboxes and databases that don't have bools yet

  •  04-28-2008, 11:09 AM

    Re: Question about checkboxes and databases that don't have bools yet

    Hi Dave,

    I should have been more specific. You need to change both the CellContentTemplate and the CellEditor in order to display a checkbox when the cell is being edited and when it is not.

    The CellEditorBinding markup extension can only be used within the context of a cell editor, it will do nothing when used in the CellContentTemplate. That said, try something like this:

         <xcdg:DataGridControl x:Name="OrdersGrid"
                                ItemsSource="{Binding Source={StaticResource cvs_product}}">
             <xcdg:DataGridControl.Columns>
                <xcdg:Column FieldName="Discontinued">
                   <xcdg:Column.CellContentTemplate>
                      <DataTemplate>
                         <xcdg:CheckBox IsChecked="{Binding Converter={StaticResource intToBooleanConverter}}" />
                      </DataTemplate>
                   </xcdg:Column.CellContentTemplate>
                   <xcdg:Column.CellEditor>
                      <xcdg:CellEditor>
                         <xcdg:CellEditor.EditTemplate>
                            <DataTemplate>
                               <xcdg:CheckBox IsChecked="{xcdg:CellEditorBinding Converter={StaticResource intToBooleanConverter}}" />
                            </DataTemplate>
                         </xcdg:CellEditor.EditTemplate>
                      </xcdg:CellEditor>
                   </xcdg:Column.CellEditor>
                </xcdg:Column>
             </xcdg:DataGridControl.Columns>
          </xcdg:DataGridControl>

     The intToBooleanConverter static resource used a a converter simply converts your 0 or 1 value to a boolean and back. In your case, I recommend using a converter rather than DataTriggers. Like such:

    // declared in the resources of your main window

    <local:IntToBooleanConverter x:Key="intToBooleanConverter" />

      public class IntToBooleanConverter: IValueConverter
      {
        public object Convert( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )
        {
          if( value is int && ( int )value == 1 )
            return true;

          return false;
        }

        public object ConvertBack( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )
        {
          if( value is bool && ( bool )value == true )
            return 1;

          return 0;
        }
      }

     Hope this clears things up!


    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
View Complete Thread
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.