Reputation: 1529
I have created a Grid in c# under silverlight like this:
Grid g = new Grid();
This grd "g
" contains 3 row and 3 column.
and i want to display at cell(2,2)(row, column)
using c#
code only (No xaml code).
but i dont know statically the number of Radiobuttons to be created, The numbers of button to be created are know dynmically by calling a function FunctionCount(..);
I know i have to do something like:
int NumberOfButtonsToBeCreated = FunctionCount(..);
for (int i = 1; i <= NumberOfButtonsToBeCreated; i++) {
RadioButton rb[i] = new RadioButton();
}
The first problem is rb[i] it don't work.And the second problem will be how to display all of them in same grid cell(2,2) one after other with a text like this :
How to achieve could some one please help me to give a pece of code with explanation to make as reference for doing this? Thanks a lot.
Upvotes: 0
Views: 529
Reputation: 964
You can use a StackPanel
to group your RadioButtons together:
Grid g = new Grid();
StackPanel sp = new StackPanel();
for (int i = 0; i < NumberOfButtonsToBeCreated; i++)
{
RadioButton rb = new RadioButton();
rb.GroupName = "myButtons";
rb.Content = "text to display";
sp.Children.Add(rb);
}
Grid.SetRow(sp, 2);
Grid.SetColumn(sp, 2);
g.Children.Add(sp);
Don't forget to set the GroupName to make the buttons mutually exclusive.
Upvotes: 1