Can we render two UI element at same grid position in SelectionChanged event of a combo box.
The exact problem is i have grid and inside the grid there are two rows the first row will always show me a ComboBox(of which i was talking about line before) on selecting different item will render different UI elemnts at same position in the second row of the grid.
So i tried to do the rendering of the UI element in the SelectionChanged event of the Combo.
But the problem happening is when i select the first element then it is displayed properly but when i try to select the second UI element to be rendered at same position on Combo selection change then it gives a warning "the value is not within the expected range." at Line : "bigGrid.Children.Add(ck);"
My code to do this is:
Grid childGrid = createChildGrid();
Grid ck = new Grid(); //This ck will contain ComboBox at row zero and UI element at second row
ck.RowDefinitions.Add(new RowDefinition());
ck.RowDefinitions.Add(new RowDefinition());
int loopCount = 0; //This variable will help in changing the row index
if (loopCount == 0)
{
ComboBox cmb = new ComboBox();
//Here i add items in Combo:
foreach(string ccyp in attributeName)
{
if (ccyp != null)
cmb.Items.Add(ccyp);
}
cmb.SelectionChanged += (o, e) =>
{
txtblkName.Text = cmb.SelectedValue.ToString();
ck = generateUIElementCorrespondingTotxtLabelNameObtainedOnComboSelection(txtblkName.Text); //this function will return a grid containing the selected UI elemnt from combo box.
Grid.SetRow(ck, loopCount);
bigGrid.Children.Add(ck); //**THIS LINE GIVE EXCEPTION: "the value is not within the expected range."**
};
}
Grid.SetColumn(cmb, 1);
childGrid.Children.Add(cmb);
Grid.SetRow(childGrid, loopCount);
bigGrid.Children.Add(childGrid);
loopCount++;// I incrtease loop count so that on selection changed event of combo UI will be displayed on second row loopcount=1
EDIT: On debugging i get :The result of break point is : loopcount=1
(for rendering of combo item in second row)this " Grid.SetRow(ck, loopCount); bigGrid.Children.Add(ck);
" and for combo box display loopcount= 0
(i mean here : "Grid.SetRow(childGrid, loopCount); bigGrid.Children.Add(childGrid); loopCount++;
")