Home Forums WPF controls Xceed DataGrid for WPF CheckBox in datagrid

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

    I am using the DatagridControl in my project, and I get some problem in using the CheckBox in the datagrid, need some help…

    I binding the IList object to the datagrid, but I need to click the cell twice for check the CheckBox.

    I had try the other EditTriggers for the datagrid, such as None,RowIsCurrent…
    But seems I need to select and active the cell, then I will be able to edit the cell, otherwise the ItemsSource of datagird will not change. Meaning If I set the EditTriggers to None, and click the cell, in this way the CheckBox is checked, but if I get the ItemsSource of the datagrid, the field mapping to the CheckBox is not changed…

    Following is my code…
    <Window.Resources>
    <DataTemplate x:Key=”dgCheckBox”>
    <StackPanel Orientation=”Horizontal” HorizontalAlignment=”Center” VerticalAlignment=”Center”>
    <CheckBox x:Name=”dgCheckBoxItem” HorizontalAlignment=”Center” VerticalAlignment=”Center” IsChecked=”{Binding Path=.}”/>
    </StackPanel>
    </DataTemplate>
    </Window.Resources>

    <xcdg:DataGridControl Background=”{x:Null}” BorderBrush=”{x:Null}” x:Name=”dgItem” SelectionMode=”Single” ItemScrollingBehavior=”Immediate”
    AutoCreateColumns=”False” EditTriggers=”SingleClick”>
    <xcdg:DataGridControl.View>
    <xcdg:TableView>
    <xcdg:TableView.Theme>
    <xcdg:AeroNormalColorTheme/>
    </xcdg:TableView.Theme>
    </xcdg:TableView>
    </xcdg:DataGridControl.View>
    <xcdg:DataGridControl.Columns>
    <xcdg:Column FieldName=”ID” ReadOnly=”True” Title=”ID”/>
    <xcdg:Column FieldName=”Name” Title=”Name” />
    <xcdg:Column FieldName=”IsNew” Title=”New Item” CellContentTemplate=”{StaticResource dgCheckBox}”/>
    </xcdg:DataGridControl.Columns>
    </xcdg:DataGridControl>

    Imported from legacy forums. Posted by yingnan (had 1534 views)

    Xceed Support
    Member
    Post count: 5658

    The CellContentTemplate determines how the content of a cell is displayed and has nothing to do with editing. In your case, you will need to provide a cell editor through the column’s CellEditor property.

    Refer to the <a href=”http://doc.xcd/XceedWpfDataGrid/Custom%20Cell%20Editors.html”>Custom Cell Editors</a> topic for information and examples.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 408 views)

    User (Old forums)
    Member
    Post count: 23064

    The link is un-accessible…

    I am the beginner in XCeed Datagrid…

    I look into the CellEditor in the sample documentation, and I find the ActivationGesture using the Key or TextInput to active the cell edit mode. What should I do for the CheckBox if I want the active the editing by the click action.

    Another question, I set the HorizontalAlignment=”Center” VerticalAlignment=”Center” in XAML file, but when I BeginEdit(), the CheckBox auto layout to HorizontalAlignment=”Left” VerticalAlignment=”Top”. How can I keep the layout for the CheckBox…

    Thanks

    Imported from legacy forums. Posted by yingnan (had 840 views)

    User (Old forums)
    Member
    Post count: 23064

    I am also facing the same problem… any idea how this is fixed?

    Imported from legacy forums. Posted by austin (had 421 views)

    Xceed Support
    Member
    Post count: 5658
    User (Old forums)
    Member
    Post count: 23064

    Hi Marcus,

    I am able to add a checkbox(center alignted to column), but the problem is when i bind data to the control, it doens’t show up the custom check box ( i believe it shows the grid’s checkbox control which is non-editable). When refreshed like reloading the data to the custom collection and re-binding the data, the checkbox is placed and in right pace.

    What could be the reason?

    Following code i have got

    <b>Under Xceed.DataGridControl.Resources</b>
    <color=”Blue”>
    <xcdg:CellEditor x:Key=”checkBoxTemplate”>
    <xcdg:CellEditor.EditTemplate>
    <DataTemplate>
    <CheckBox IsChecked=”{Binding Path=.}” HorizontalAlignment=”Center”
    Checked=”CustomerAccessibleCheckBox_Toggled”
    Unchecked=”CustomerAccessibleCheckBox_Toggled” />
    </DataTemplate>
    </xcdg:CellEditor.EditTemplate>
    <xcdg:CellEditor.ActivationGestures>
    <xcdg:KeyActivationGesture Key=”Space”/>
    </xcdg:CellEditor.ActivationGestures>
    </xcdg:CellEditor>
    </color>
    <b>Under Xceed.DataGridControl.Columns</b>
    <color=”Blue”>
    <xcdg:Column FieldName=”CustomerAccessible” Title=”Customer Accessible”
    CellEditor=”{StaticResource checkBoxTemplate}” />
    </color>

    Imported from legacy forums. Posted by austin (had 819 views)

    User (Old forums)
    Member
    Post count: 23064

    You need to change CellContentTemplate as well 🙂

    Imported from legacy forums. Posted by nat (had 969 views)

    User (Old forums)
    Member
    Post count: 23064

    It worked!!! Thanks!!!

    Imported from legacy forums. Posted by austin (had 447 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi,
    For your question :
    I binding the IList object to the datagrid, but I need to click the cell twice for check the CheckBox.

    you have just to set the property CellEditorDisplayConditions like this for you column :

    objXceedDataGridColumn.CellEditorDisplayConditions = CellEditorDisplayConditions.MouseOverCell

    Imported from legacy forums. Posted by akachouche (had 6646 views)

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