简体   繁体   中英

Radio button in Gridcolumn won't trigger binding

I have two devexpress gridcolumns with one radio button in each.

In code behind when I am setting a value to the properties binding to the radio button, the binding takes. But when I am changing selected radio button in the view the selected won't trigger the property.

what am I missing?

<dxg:GridColumn Binding="{Binding IsOrder}"
                      Header="Order" 
                      Visible="{Binding IsVisible}"
                      Width="60">
  <dxg:GridColumn.CellTemplate>
        <DataTemplate>
            <RadioButton IsChecked="{Binding Path=Value, Mode=TwoWay}"
                         GroupName="{Binding RowData.Row.Number}"
                         VerticalAlignment="Center"
                         HorizontalAlignment="Center"
                        IsEnabled="{Binding 
                               Path=View.DataContext.StatusNotHandled}"/>
       </DataTemplate>
</dxg:GridColumn.CellTemplate>

<dxg:GridColumn Binding="{Binding IsNotOrder}"
                      Header="Not order" 
                      Visible="{Binding IsVisible}"
                      Width="60">
  <dxg:GridColumn.CellTemplate>
        <DataTemplate>
            <RadioButton IsChecked="{Binding Path=Value, Mode=TwoWay}"
                         GroupName="{Binding RowData.Row.Number}"
                         VerticalAlignment="Center"
                         HorizontalAlignment="Center"
                        IsEnabled="{Binding 
                                Path=View.DataContext.StatusNotHandled}"/>
       </DataTemplate>
</dxg:GridColumn.CellTemplate>

The cause of your problem is most likely the fact that you are trying to use a non-DX control as an edit of a GridColumn which is discouraged explicitly by DevExpress. Try replacing the RadioButton with a DX-CheckEdit for example.

Key-take-aways from my experience:

  1. do NOT use non-DX controls as InplaceEdits of a GridControl.
  2. for DX-edits to work correctly when assigned in a CellTemplate their name has to be set to 'PART_Editor'. Omitting that will lead to problems with navigation etc.
  3. Use the the GridColumn.FieldName-property instead of binding. This should make the InplaceEdit inherit the binding from its Column automatically.

Change your binding for IsChecked to RowData.Row.IsOrder , it will probably solve your selection problem. You can read a little bit more information on using RowData.Row over Value or Data here .

On another note, as @Sancho Panza said, you're always better to stick with BaseEdit descendant when dealing with CellTemplate.

This is one of the advantages of using a BaseEdit descendant in CellTemplate :

For the DevExpress Data Editors (the BaseEdit class's descendants), you can set the editor's Name property to PART_Editor. In this case, the GridControl automatically adjusts its appearance and synchronizes the editor with the source field specified by the ColumnBase.FieldName or ColumnBase.Binding properties.
You can use any binding with an editor named PART_Editor. In this case, the GridControl's logic of getting/setting the editor's value is disabled.

The final decision of using a BaseEdit descendant or a WPF RadioButton is yours, but I also recommend sticking with BaseEdit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM