Ejemplo n.º 1
0
        private void FillComboItems(ComboBoxEx comboBox, IEnumerable <ComboItem> items)
        {
            //保持原有选项
            var oldSelection = comboBox.SelectedItem as ComboItem;
            int?newSelection = null;

            comboBox.BeginUpdate();
            comboBox.Items.Clear();

            foreach (var item in items)
            {
                comboBox.Items.Add(item);

                if (newSelection == null && oldSelection != null)
                {
                    if (item.Text == oldSelection.Text)
                    {
                        newSelection = comboBox.Items.Count - 1;
                    }
                }
            }

            //恢复原有选项
            if (comboBox.Items.Count > 0)
            {
                comboBox.SelectedIndex = newSelection ?? 0;
            }

            comboBox.EndUpdate();
        }
Ejemplo n.º 2
0
 /// <inheritdoc/>
 public override void UpdateContent()
 {
     cbxObjects.BeginUpdate();
     try
     {
         cbxObjects.Items.Clear();
         if (Designer.ActiveReport != null)
         {
             Report report = Designer.ActiveReport.Report;
             SortedList <string, Base> sl = new SortedList <string, Base>();
             sl.Add("", report);
             foreach (Base c in report.AllObjects)
             {
                 if (!sl.ContainsKey(c.Name))
                 {
                     sl.Add(c.Name, c);
                 }
             }
             foreach (Base c in sl.Values)
             {
                 cbxObjects.Items.Add(c);
             }
         }
         SelectionChanged();
     }
     finally
     {
         cbxObjects.EndUpdate();
     }
 }