views:

2090

answers:

2

With the new release of Silverlight 3 and the move of the DataForm to the SilverLight Toolkit - does anyone know how to programatically add items to a combobox in a DataForm? There doesn't seem to be any of accessing it via the code file/

Thanks ~Steve

+4  A: 

Yes, you can manage it by

dataForm.ContentLoaded += (sender, args) =>
{
    TextBox myTextBox = (TextBox)dataForm.FindNameInContent("myTextBox");
    // do something with the TextBox...
};

Look in here for details: http://silverlight.net/forums/t/108278.aspx

VojTas
Works perfectly! Thank you very much. I didn't realize it had to go in the ContentLoaded event.
Steve French
A: 

private void dataForm_ContentLoaded(object sender, DataFormContentLoadEventArgs e)
{

Dictionary products= GetProducts();
foreach (string key in products.Keys)
{
ComboBoxItem listBoxItem = new ComboBoxItem();
ComboBox cmbProducts = (ComboBox)dataForm.FindNameInContent
("cmbProducts");
listBoxItem.Name = cmbProducts.Name + key;
listBoxItem.Content = key;
cmbProducts.Items.Add(listBoxItem);
}
}
On the XAML declare teh event for ur dataForm.

Dipen Lama

related questions