views:

244

answers:

1

I have been trying to find out how to bind data to a
System.Windows.Forms.DomainUpDown() control.

Currently I have only come up with:

        private void Init()
        {
            List<string> list = new List<string>();
            list = get4000Strings(); //4000 items

            foreach (string item in list)
            {
                domainUpDown1.Items.Add(item); 
            }

        }

        private List<string> get4000Strings()
        {
            List<string> l = new List<string>();
            for (int i = 0; i < 4000; i++)
            {
                l.Add(i.ToString());
            }
            return l;
        }
+1  A: 

The DomainUpDown.Items collection has an AddRange() method that takes an ICollection (implemented by List<T>), so you could just do

private void Init() {
  List<string> list = new List<string>();
  list = get4000Strings(); //4000 items
  domainUpDown1.Items.Clear();
  domainUpDown1.Items.AddRange(list);
}

However, if you have that much items to show, I would suggest you use a ComboBox having DropDownStyle set to DropDownList. It will allow you to databind directly to the list (e.g. comboBox1.DataSource = list;), especially if the list changes often, as you won't have to refill the ComboBox each time, just change the datasource...

Julien Poulin