Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Fill combobox with objects (other than strings) (See related posts)

        public static void FillComboBoxWithOids(ComboBox comboBox)
        {
            comboBox.Items.Clear();

            List<string> oids = GetColumnValues(OidColumns.COL_OID);
            List<string> infos = GetColumnValues(OidColumns.COL_INFO);

            comboBox.Items.Add(new ComboBoxOidItem("", "-"));
            if ((oids != null) && (infos != null))
                for (int i = 0; i < oids.Count; i++)
                    comboBox.Items.Add(new ComboBoxOidItem(oids[i], infos[i]));

        }
        public class ComboBoxOidItem
        {
            public ComboBoxOidItem(string OID, string name)
            {
                _oid = OID;
                _name = name;
            }

            string _oid = null;
            string _name = null;

            public override string ToString()
            {
                return _name;
            }

            public string Name
            {
                get
                {
                    return _name;
                }
            }

            public string Oid
            {
                get
                {
                    return _oid;
                }
            }
        }

You need to create an account or log in to post comments to this site.


Click here to browse all 4861 code snippets

Related Posts