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

DataTemplate with RadioButton in dynamic xaml

2 Answers 166 Views
GridView
This is a migrated thread and some comments may be shown as answers.
lina fetisova
Top achievements
Rank 1
lina fetisova asked on 17 Jun 2010, 06:58 AM
Good day!

I have a form with a stack panel of questions. Each question has a number of answers which look like a list of radiobuttons.
I make my xaml dynamically:

<StackPanel x:Name="spQuestions" Orientation="Vertical" Grid.Column="1" Grid.Row="8" Grid.ColumnSpan="3" HorizontalAlignment="Left">
</StackPanel>


foreach (QuestionDTO question in questions)
            {
                StackPanel newsp = new StackPanel();
                newsp.Orientation = Orientation.Vertical;
                TextBlock textBlock = new TextBlock();
                textBlock.Text = question.Text;
                newsp.Children.Add(textBlock);
                   RadGridView gridView = new RadGridView();
                    gridView.Name = "grAnsw" + question.Id.ToString();
                    gridView.ItemsSource = question.Answers;
                    gridView.AutoGenerateColumns = false;
                    gridView.IsReadOnly = true;
                    GridViewRadioButtonColumn col = new GridViewRadioButtonColumn();    
                    gridView.Columns.Add(col);
                    newsp.Children.Add(gridView);
                    spQuestions.Children.Add(newsp);
       }


where

public class GridViewRadioButtonColumn : GridViewDataColumn
{
        public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem)
        {
            var radioButton = cell.Content as RadioButton;
            if (radioButton == null)
            {
                radioButton = new RadioButton();
                radioButton.SetBinding(RadioButton.ContentProperty, new Binding("Text")
                {
                  Source = dataItem
                });
                cell.Content = radioButton;
            }
            return radioButton;
        }
}


In the result I have the page which I wanted, but all radio buttons look like they are in the same list. So I can check only one radiobutton on the page, but I want to check one radiobutton in one question, but there are a number of questions on the page =(
How can I make the page see that there are different lists of radiobuttons for each question?

Thank you.

2 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 17 Jun 2010, 07:18 AM
Hello,

 You may need to set GroupName for these buttons. 

All the best,
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.
0
lina fetisova
Top achievements
Rank 1
answered on 21 Jun 2010, 07:57 AM
Vlad, that's great! thank you very much! everything is allright! =))))
Tags
GridView
Asked by
lina fetisova
Top achievements
Rank 1
Answers by
Vlad
Telerik team
lina fetisova
Top achievements
Rank 1
Share this question
or