Home Forums WPF controls Xceed DataGrid for WPF check box in data grid

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #24191 |

    Hello,

    I am trying to put a check box in the last column of a DataGridControl
    (version 1.2) and I have problems trying to bind the check box
    with the source.

    I have a DataGridControl, and CollectionViewSource is a
    List<MyClass> MySource. Last column in the grid should be a CheckBox
    bounded to MyClass.ToApply .
    The result: I see the databaseValues in the first column of my grid but
    the check box does not reflect toApply. I know something is wrong with the
    binding what is it?

    public class MyClass
    {
    string databaseValue;
    bool toApply;


    }

    ….

    List<MyClass> MySource;
    ….
    ….

    This is my XAML code:

    <ContentControl>
    <ContentControl.Resources>
    ….
    <!–Define the template for the last column to contain a CheckBox
    control–>
    <DataTemplate x:Key=”CheckBoxCell”>
    <StackPanel Orientation=”Horizontal”>
    <CheckBox Margin=”42,0,0,0″ IsChecked= {Binding Path=ToApply}”/>
    </StackPanel>
    </DataTemplate>
    ….
    </ContentControl.Resources>

    <!–Grid control declaration.–>
    <xcdg:DataGridControl x:Name=”MyGrid”
    DockPanel.Dock=”Bottom”
    ItemsSource=”{Binding Source={StaticResource MySource}}”
    ReadOnly=”False”
    ItemScrollingBehavior=”Immediate”
    CellEditorDisplayConditions=”None”
    AutoCreateColumns=”False”
    SelectionMode=”Single”
    NavigationBehavior=”RowOnly”
    PagingBehavior=”TopToBottom”
    Width=”Auto”
    Height=”Auto”>
    <xcdg:DataGridControl.Columns>

    <xcdg:Column FieldName=”DatabaseValue”
    Title=”Value”
    Width=”330″
    VisiblePosition=”3″
    ReadOnly=”True”
    DisplayMemberBinding=”{Binding Path=DatabaseValue}”>

    <xcdg:Column FieldName=”Apply”
    Title=”Apply”
    Width=”90″
    VisiblePosition=”5″
    ReadOnly=”False”
    CellContentTemplate=”{StaticResource CheckBoxCell}”>
    </xcdg:Column>

    </xcdg:DataGridControl.Columns>
    </xcdg:DataGridControl>

    </ContentControl>

    Thanks

    Tatiana

    Imported from legacy forums. Posted by tivanova (had 548 views)

    Xceed Support
    Member
    Post count: 5658

    Change the FieldName of the “Apply” column to “ToApply” ( The column’s fieldName has to match the Field Name, to change the displayed title, refer the Title property)…

    Also, in the CellContentTemplate, the Binding should have the path of “.” instead of “ToApply”, since the content template is to be applied to the cells content.

    Note: if the checkbox is meant to be interractive… you should probably instead set the CellEditorDisplayConditions to Always and build a CheckBox cell editor.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 278 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks Marcus

    Actually I know the answer now (my colleague helped me):

    I needed to add to my initial code:

    <CheckBox Margin=”42,0,0,0″ IsChecked=”{Binding RelativeSource ={RelativeSource FindAncestor, AncestorType={x:Type xcdg:DataCell}}, Path= DataContext.ToApply}”/>

    and it will work two ways (in and out) without renaming the field. And no cell editor needed.

    Tatiana

    Imported from legacy forums. Posted by tivanova (had 252 views)

    Xceed Support
    Member
    Post count: 5658

    True, but be warned that proceeding that way forfeits most of the In-Place edition mechanisms:

    – Cancel\Commit possibilities
    – Validation

    Imported from legacy forums. Posted by Marcus [Xceed] (had 3721 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.