This is the code i have written to dynamically generate Controls:
private void GenCtrl(string type, int typeid,string sql)
{
string id = Convert.ToString(typeid);
if (type == "TextBox")
{// created for TextBox
}
else if (type == "ComboBox")
{
ComboBoxEdit cb = new ComboBoxEdit();
cb.Name = "cb" + id;
// this is to set unique id if more than 1 combobox created.
cb.Height = 20;
cb.Width = 100;
cb.Margin = new Thickness(2, 2, 0, 0);
cb.HorizontalAlignment = HorizontalAlignment.Left;
cb.Text = "Show All";
stctrl.Children.Add(cb);
ComboBoxEdit cbx = (ComboBoxEdit)cb.FindName(cb.Name);
cb.DisplayMember = "Name";
if(filsql !=null)
ServRef.GetComboBoxlistAsync(sql); //this would retrieve the list and attach to the combobox.
//ctlst.Add(cb.Name, type);
}
}
//WCF Service reference
ServRef.GetComboBoxlistCompleted += new EventHandler<GetComboBoxlistCompletedEventArgs>(ServRef_GetComboBoxlistCompleted);
void ServRef_GetComboBoxlistCompleted(object sender, GetComboBoxlistCompletedEventArgs e)
{
cb.ItemsSource = e.Result;
cb.SelectedIndex = 0;
}
The problem i am facing while binding two combobox is created ex : cb1,cb2( dynamically created)only the control cb2 combox which is the latest get activated at ServRef_GetComboBoxlistCompleted method. i am unable to bind the value for the first control(combobox).
if my question is not clear let me know.