I want to add default item like "--Select--" in combobox for silverlight 3 for both static/dynamic population of combo box.
Here is the sample code.Please Help.
List
{
new date() {Name="Mins"},
new date() {Name="Hour"},
new date() {Name="Day"},
new date() {Name="Week"},
new date() {Name="Month"},
new date() {Name="Year"}
};
cmbPerweek1.ItemsSource = _date;
// cmbPerweek1.Items.Add("--Select Time Interval--");
cmbPerweek1.Items.Insert(0,"--Select Time Interval--");
cmbPerweek1.SelectedIndex = 0;
This is one type and another dropdown is loaded from Service.How to add for that too.When it run the Application it displays
"Operation not supported on read-only collection."..
Thanks in Advance.
Priya LingePosted Oct 18, 2011, 2:22 AM
Hi,
Please try this.
MainPage.Xaml :
MainPage.xaml.cs :
public partial class MainPage : UserControl
_date = new List()
{
public MainPage()
{
InitializeComponent();
List
{
new dataclass() {Name="Mins"},
new dataclass() {Name="Hour"},
new dataclass() {Name="Day"},
new dataclass() {Name="Week"},
new dataclass() {Name="Month"},
new dataclass() {Name="Year"}
};
// comboBox1.ItemsSource = _date.ToList();
comboBox1.Items.Add("--Select--");
comboBox1.SelectedIndex = 0;
for (int i = 0; i < _date.Count; i++)
{
comboBox1.Items.Add(_date[i].Name.ToString());
}
}
}
public class dataclass
{
private string name;
public string Name
{
get { return name;}
set { name = value; }
}
}
Please chk attached code file.
Hope this will help you.
Thanks.