This is a migrated thread and some comments may be shown as answers.

GridView With Radiobutton column

3 Answers 446 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Kiran
Top achievements
Rank 1
Kiran asked on 21 Sep 2010, 10:49 AM
Hi

I have a requirement where I need to add a radiobutton as first column of the grid and when the user selects the radiobutton the row should be selected I mean selecteditem should be set for the grid. I have used the below code to show the radio button in the grid but I am not able bind the radiobutton selection to the SelectedItem.

<telerik:GridViewDataColumn Name="GridColumnSelector" Header="">
    <telerik:GridViewDataColumn .CellTemplate>
        <DataTemplate>
               <RadioButton Name="rdCheck" GroupName="RadioSelectors" />
        </DataTemplate>
    </telerik:GridViewDataColumn .CellTemplate>
</telerik:GridViewDataColumn >

Regards
Kiran

3 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 21 Sep 2010, 11:11 AM
Hi Kiran,

You may handle the Checked event of the RadioButton and find its parent row by using the ParentOfType<> extension method. Afterwards, all you need to do is to set that particular row to be the selected one:

private void rdCheck_Checked(object sender, RoutedEventArgs e)
{
    RadioButton radioButton = sender as RadioButton;
    GridViewRow parentRow = radioButton.ParentOfType<GridViewRow>();
    if(parentRow != null)
    {
        parentRow.IsSelected = true;
    }
}

You may find more information about the ParentOfType<> extension method in this blog post.

 

Sincerely yours,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Kiran
Top achievements
Rank 1
answered on 21 Sep 2010, 11:38 AM
Hi

Thanks for prompt response. I implemented the same way as before but now I get following error. I am not sure if I have to add any references. 

private void RadioRowSelection_Click(object sender, RoutedEventArgs e)
{
     RadioButton radioButton = sender as RadioButton;
     GridViewRow parentRow = radioButton.ParentOfType<GridViewRow>();
     if (parentRow != null)
     {
          parentRow.IsSelected = true;
     }
  
}


'System.Windows.Controls.RadioButton' does not contain a definition for 'ParentOfType' and no extension method 'ParentOfType' accepting a first argument of type 'System.Windows.Controls.RadioButton' could be found (are you missing a using directive or an assembly reference?)

Regards
Kiran
0
Accepted
Vlad
Telerik team
answered on 21 Sep 2010, 11:43 AM
Hi,

 You need:

using Telerik.Windows.Controls;

Sincerely yours,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Kiran
Top achievements
Rank 1
Answers by
Maya
Telerik team
Kiran
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or