0
votes
<dxg:GridControl x:Name="m_grid" SelectionMode="Row" AutoGenerateColumns="AddNew" ItemsSource="{Binding Path=MyDT,Mode=TwoWay}">
    <dxg:GridControl.Columns>
        <dxg:GridColumn x:Name="col_A" AllowEditing="False" FieldName="A" />
        <dxg:GridColumn x:Name="col_B" AllowEditing="False" FieldName="B" />
        <dxg:GridColumn x:Name="col_C" AllowEditing="False" FieldName="C" />
        <dxg:GridColumn x:Name="col_D" AllowEditing="False" FieldName="D" />
        <dxg:GridColumn x:Name="col_E" AllowEditing="True" FieldName="E" />
    </dxg:GridControl.Columns>
</dxg:GridControl>

I have a Grid control in a wpf application am developing using MVVM design battern. My GridControl is bound to a DataTable in my view model "MyDT". Now one of the columns in "MyDT" is of type bool, so the GridControl converts it to a checkbox. This is the only column in my GridControl which is editable, the remaining columns are uneditable, I have made sure in the xaml. What I need to do is trigger an event when a checkbox is ticked/unticked in any of the rows in the GridControl, by binding to a property in my viewmodel. How would the xaml change?

2
are you trying to have a checkbox column column to select data rows? - Xi Sigma
I am not sure I follow your question. Initially all checkboxes are unticked in the grid control since the datatable it is bound to in view model class has initialized that particular column value to false. Now when a user clicks on the checkbox I need to trigger an event which involves doing some other processing like calling a function in a separate user control etc. - user3821877

2 Answers

0
votes

A property is already bound to your checkbox, that is the property in your dt

If you want to deliberately handle check event.. add a checkBoxColumn or templated column instead of Grid Column..

that ways you will have access to checked event or associated command.

0
votes

Assuming you have an ICommand named CheckBoxCommand in your ViewModel

<dxg:GridColumn>
    <dxg:GridColumn.CellTemplate>
        <DataTemplate>
            <dxe:CheckEdit 
                Command="{Binding Path=View.DataContext.CheckBoxCommand}" 
                CommandParameter="{Binding RowData.Row}"/>
        </DataTemplate>
    </dxg:GridColumn.CellTemplate>
</dxg:GridColumn>

note that the command parameter is actually your Model so in your ViewModel you can have a command like:

private ICommand _checkBoxCommand;
public ICommand CheckBoxCommand
{
    get
    {
        return _checkBoxCommand = _checkBoxCommand ?? new RelayCommand((param) =>
            {
                var model = param as Model;

                // Do whatever with the model.

            });
    }
}