Hi,
One of my friend was having a problem in implementing the radio button in datagrid, if implemented he wanted to know how to group them so that in 2 different columns radio button will be grouped as one. So after few attempts I found the following method and explained him the implementation.
To implement a radio button you have to use the DataGridTemplateColumn, where you can create your custom column for datagrid.
The radio button was quite easily implemented as the following code
<dg:DataGridTemplateColumn
Header="Male">
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<RadioButton IsChecked="{Binding Male}" />
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
<dg:DataGridTemplateColumn
Header="Female">
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<RadioButton IsChecked="{Binding Female}" />
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>

After the implementation of the radio button we faced a challenge to group it up and we came with a very beautiful idea of giving a group name to both of them and here is what we did, we gave a groupname as “RadioGroup” to both of the radio button as
<dg:DataGridTemplateColumn
Header="Male">
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<RadioButton GroupName="RadioGroup" IsChecked="{Binding Male}" />
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
<dg:DataGridTemplateColumn
Header="Female">
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<RadioButton GroupName="RadioGroup" IsChecked="{Binding Female}" />
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>

Oops we were again into a problem, now all the cells were grouped together so we could select only one out of whole group.
Think Think Think is what we did, then we got a idea to have a group name that is unique for each row that is created. So we created a property called index which will be unique across each person, and we binded our column with the index, so that for each person instance the index will be same but not for 2 persons in the collection.
And this gave us the final solution of grouped radio button. Here is what we did.
<dg:DataGridTemplateColumn
Header="Male">
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<RadioButton GroupName="{Binding Index}" IsChecked="{Binding Male}" />
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
<dg:DataGridTemplateColumn
Header="Female">
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<RadioButton GroupName="{Binding Index}" IsChecked="{Binding Female}" />
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>

So the main thing that has to be noted is, we should have a property that will remain unique accross the collection. If we have such property just bind it with the groupname and radio button will work absolutely fine.
Hope you found it useful. For any clarification or any better suggestions please revert back.
Happy Learning,
Codingsense










