Link to home
Start Free TrialLog in
Avatar of bkrbbnsEE
bkrbbnsEEFlag for United States of America

asked on

WPF datagrid with radiobuttons added. How do I get which has been selected?

I'm new to wpf.  I'm using vs 2010 and the code behind is vb.net.  I've created a datagrid that gets a description from a SQL Server table and populates the description to a row with 3 radiobuttons. Each row has a unique groupname for the three radiobutons.  The user can then read the description and select the appropriate button.  

My question is how to do I get which radiobutton was selected in each row using  the code behind?

I set the datacontext of the datagrid to a table and the description field  populates correctly and you can only select one radiobutton in the group but I'm not sure how to determine which was selected in each row.

My xaml is below.


                    <DataGrid Width="Auto" VerticalAlignment="Top" Height="Auto" ItemsSource="{Binding}" AutoGenerateColumns="False" CanUserAddRows="False" Name="dgrd1">
                    <DataGrid.Columns>
                        <DataGridTemplateColumn Header="Electrical Safety/Lockout/Tagout(LOTO)" Width="Auto" IsReadOnly="True">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBox Name="Description1" Text="{Binding Path=DETAIL_DESCRIPTION, Mode=OneWay}" Height="75" Width="250" IsReadOnly="True" TextWrapping="Wrap"></TextBox>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTemplateColumn Header="PASS" Width="Auto" IsReadOnly="True">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <RadioButton Name="rdbPass1" Content="PASS" Height="Auto" Width="75" GroupName="{Binding Path=GROUP_ID}"></RadioButton>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTemplateColumn Header="FAIL" Width="Auto" IsReadOnly="True">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                        <RadioButton Name="rdbFail1" Content="FAIL" Height="Auto" Width="75" GroupName="{Binding Path=GROUP_ID}"></RadioButton>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTemplateColumn Header="NA" Width="Auto" IsReadOnly="True">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                        <RadioButton Name="rdbNA1" Content="NA" Height="Auto" Width="75" GroupName="{Binding Path=GROUP_ID}"></RadioButton>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTemplateColumn Header="Action Require" Width="Auto" IsReadOnly="True">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                        <TextBox Name="ActionRequired1" Text="" Height="75" Width="150" IsReadOnly="False" TextWrapping="Wrap" AcceptsReturn="True"></TextBox>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTemplateColumn Header="Person Responsible" Width="Auto" IsReadOnly="True">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                        <TextBox Name="PersonResponsible1" Text="" Height="75" Width="150" IsReadOnly="False" TextWrapping="Wrap" AcceptsReturn="True"></TextBox>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                    </DataGrid.Columns>
                </DataGrid>



I've tried:

 For i As Integer = 0 To dgrd1.Items.Count - 1
            For j As Integer = 0 To dgrd1.Columns.Count - 1
                strItem = dgrd1.Items(i).ToString
                Dim s As String = TryCast(dgrd1.Items(i), DataRowView).Row.ItemArray(j).ToString()
            Next
        Next
i can see the fields from my data table, do I need to add columns in my datatable for the radiobuttons?
ASKER CERTIFIED SOLUTION
Avatar of bkrbbnsEE
bkrbbnsEE
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial