示例#1
0
        public static void SetDataSource <T>(this ComboBox control, List <IComboBoxData <T> > DataSource, bool IncludedAll, object selectedvalue)
        {
            if (DataSource != null)
            {
                if (IncludedAll)
                {
                    ComboSelectAll <T> cboAll = new ComboSelectAll <T>();
                    DataSource.Insert(0, cboAll);
                }

                control.DisplayMember = "DISPLAY";
                control.ValueMember   = "VALUE";
                control.DataSource    = DataSource;

                if (selectedvalue != null)
                {
                    control.SelectedValue = selectedvalue;
                    if (!object.Equals(control.SelectedValue, selectedvalue))
                    {
                        control.SelectedIndex = -1;
                    }
                }
                else
                {
                    control.SelectedIndex = IncludedAll == true ? 0 : -1;
                }
            }
        }
示例#2
0
        public static void SetDataSource <T>(this ComboBox control, BindingList <IComboBoxData <T> > DataSource, bool IncludedAll)
        {
            if (DataSource != null)
            {
                if (IncludedAll)
                {
                    ComboSelectAll <T> cboAll = new ComboSelectAll <T>();
                    DataSource.Insert(0, cboAll);
                }

                control.DisplayMember = "DISPLAY";
                control.ValueMember   = "VALUE";
                control.DataSource    = DataSource;

                control.SelectedIndex = IncludedAll == true ? 0 : -1;
            }
        }