I am using xamDataGrid which has radio button column as control template. OnCheck on radio button column it gets checked. I have a button. I want to clear the radio button checked before on click of the button
<
igDP:XamDataGrid.Resources>
<!-- This Style puts a Radio button into the record selectors. -->
<Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="RadioButtonCheckedStyle">
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
<RadioButton x:Name="rbselector" GroupName="Test" Checked
="rbselector_Checked"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style></igDP:XamDataGrid.Resources>
//Field setting in XAMDataGrid//
igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout>
<igDP:FieldLayout.Fields>
<igDP:UnboundField Name="UB1" Label="Select" DataType="{x:Type RadioButton
}" ><igDP:Field.Settings>
<igDP:FieldSettings CellValuePresenterStyle="{StaticResource RadioButtonCheckedStyle}" AllowEdit="True" />
</igDP:Field.Settings>
</igDP:UnboundField>
I tried binding the radio button IsChecked property to a boolean property and changing the value to false on Button click event. But still the radio button is checked.
Please suggest how to uncheck the radio button on click of other button.
Absolutely, you can check only the active record. This was one example, but obviously a better way would be to retrieve the active recond, thanks for mentioning it, and the specific column where the ReadioButton is, so you don't have to iterate through the cell collection either. Here is how:
DataRecord rec = this.xamDataGrid1.ActiveRecord as DataRecord;
if (rec != null)
{
RadioButton rb =
Utilities.GetDescendantFromType(CellValuePresenter.FromCell(rec.Cells["UB1"]),
typeof(RadioButton), false) as RadioButton;
if (rb != null)
rb.IsChecked = false;
}
The "UB1" in this case is the column where the RadioButton resides.
Thanks,Sam
Thanks for your reply. It worked for me. But for better performance can't we check only active record which will have radio button checked. how can we implement if it is possible?
Hello,
With a button click you iterate through the records in xamDataGrid and reference the control (RadioButton in this case) looping through the cell. Here is a code example you can use in the button click event:
foreach (DataRecord rec in this.xamDataGrid1.Records)
foreach (Cell cell in rec.Cells)
Utilities.GetDescendantFromType(CellValuePresenter.FromCell(cell),
I hope this works for you. Let me know if you have any questions.
Sam.