/// <summary> /// Fill a checked list box with all the tags from a category, and set their check state /// A tag will be checked if there is a row in aVew whose aTagColumnName column has the tag value /// \note Its expected that aView has already been filtered for a specific item /// </summary> /*public static void FillCheckedList(CheckedListBox aCheckedList, string aCategoryName, * DataView aView, string aTagColumnName) * { * aCheckedList.BeginUpdate(); * aCheckedList.Items.Clear(); * aCheckedList.CheckOnClick = true; * * var tagSet = SystemTags.GetTagSet(aCategoryName); * foreach (var tag in tagSet.Tags.Values) * { * int index = aCheckedList.Items.Add(tag, false); * foreach (DataRowView dbRow in aView) * { * if ((int)dbRow[aTagColumnName] == tag.Value) * { * aCheckedList.SetItemChecked(index, true); * break; * } * } * } * * aCheckedList.EndUpdate(); * }*/ public static void Fill(this CheckedListBox value, string categoryName, int tagSetId) { Validation.IsNotNull(value, "value"); Validation.IsNotNullOrEmpty(categoryName, "categoryName"); value.BeginUpdate(); value.Items.Clear(); value.CheckOnClick = true; var dbContext = Program.NinjectKernel.Get <IRealmDbContext>(); var checkedTagSetList = dbContext.TagSets.Include(x => x.Tags).Where(x => x.Id == tagSetId); if (!checkedTagSetList.Any() || checkedTagSetList.Count() > 1) { value.EndUpdate(); return; } var tagList = checkedTagSetList.First().Tags.ToList(); var tagSet = SystemTags.GetTagSet(categoryName); foreach (var tag in tagSet.Tags.Values.Where(tag => tagList.Exists(x => x.Id == tag.Id))) { value.SetItemChecked(value.Items.Add(tag, false), true); break; } value.EndUpdate(); }
private void ItemPicker_Load(object sender, EventArgs e) { CatalogEditor.ItemPicker2List.Clear(); LuckyDrawBoxTool.ItemPicker2Listt.Clear(); ShopEditor.ItemPicker2Listt.Clear(); LoadStartup(); //dethunter12 add MenuList.Clear(); listBox1.BeginUpdate(); for (int index = 0; index < IconList.List.Count <ticon>(); ++index) { listBox1.Items.Add("" + IconList.List[index].ItemID.ToString() + " - " + IconList.List[index].Name.ToString()); } listBox1.EndUpdate(); }
//下拉列表事件 protected override void OnDropDown(EventArgs e) { if (IsMultiSelect) { list.Visible = !list.Visible; if (list.Visible) { list.Focus(); list.ItemHeight = this.ItemHeight; list.BorderStyle = BorderStyle.FixedSingle; list.Font = this.Font; list.Size = new Size(this.DropDownWidth, this.ItemHeight * (this.MaxDropDownItems - 1) - (int)this.ItemHeight / 2); list.Location = new Point(this.Left, this.Top + this.ItemHeight + 6); list.BeginUpdate(); if (this.DataSource != null) { list.DataSource = this.DataSource; list.DisplayMember = this.DisplayMember; list.ValueMember = this.ValueMember; } list.EndUpdate(); if (!this.Parent.Controls.Contains(list)) { this.Parent.Controls.Add(list); list.BringToFront(); } } } }
protected override void OnDropDown(EventArgs e) { lst.Visible = !lst.Visible; if (!lst.Visible) { //this.Focus(); return; } lst.Focus(); lst.ItemHeight = this.ItemHeight; lst.BorderStyle = BorderStyle.FixedSingle; lst.Size = new Size(this.DropDownWidth, this.ItemHeight * (this.MaxDropDownItems - 1) - (int)this.ItemHeight / 2); lst.Location = new Point(this.Left, this.Top + this.ItemHeight + 6); lst.BeginUpdate(); lst.Items.Clear(); for (int i = 0; i < this.itemsList.Count; i++) { lst.Items.Add(this.itemsList[i]); if (this.checkedValues.ContainsKey(this.itemsList[i])) { lst.SetItemChecked(i, true); } } lst.EndUpdate(); if (!this.Parent.Controls.Contains(lst)) { this.Parent.Controls.Add(lst); } lst.BringToFront(); }
public static void PopulateFilterList(CheckedListBox list, List <Filter> filters, bool setFalse = false) { list.BeginUpdate(); int index = list.SelectedIndex; if (list.Items.Count > 0) { list.Items.Clear(); } for (int i = 0; i < filters.Count; i++) { list.Items.Add(filters[i].Name); if (!setFalse) { list.SetItemChecked(i, filters[i].Enabled); } } if (index >= 0 && index < list.Items.Count) { list.SelectedIndex = index; } list.EndUpdate(); }
// Implementazione Filtro mediante TextBox -> Tab generato dal file di configurazione XML private void BoxRicercaXml_TextChanged(object sender, EventArgs e) { if (_lsXml != null) { // Filtro listaImmagini in base alla ricerca fatta dall'utente, mantenendo i valori checked. listaXml.BeginUpdate(); List <string> selected = listaXml.CheckedItems.Cast <string>().ToList(); // Gli item selezionati vanno riaggiunti listaXml.Items.Clear(); foreach (string name in _lsXml) { if (!string.IsNullOrEmpty(name)) { if (selected.Contains(name)) { listaXml.Items.Add(name, true); } else { if (name.ToLower().Contains(((TextBox)sender).Text.ToLower())) { listaXml.Items.Add(name); } } } } listaXml.EndUpdate(); } }
private void FillOutDatabaseObjectNames(string cmdName, CheckedListBox clb, DatabaseObjectType objectType) { string objectName; string strCmd = ConfigurationManager.AppSettings[cmdName]; Database db = DatabaseFactory.CreateDatabase(); Action beginUpdate = () => clb.BeginUpdate(); clb.Invoke(beginUpdate); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strCmd)) { Action addItem; while (reader.Read()) { objectName = reader.GetString(0); addItem = () => clb.Items.Add(new ListItem() { Value = objectName, Type = objectType }); clb.Invoke(addItem); } } Action endUpdate = () => clb.EndUpdate(); clb.Invoke(endUpdate); }
public static void LoadItems(this CheckedListBox listBox, Object[] items) { listBox.BeginUpdate(); listBox.Items.Clear(); listBox.Items.AddRange(items); listBox.EndUpdate(); }
private void SetAllDatabaseObjectSelected(CheckedListBox dbObjectList, CheckBox chkAll) { dbObjectList.BeginUpdate(); for (int i = 0; i < dbObjectList.Items.Count; i++) { dbObjectList.SetItemChecked(i, chkAll.Checked); } dbObjectList.EndUpdate(); }
void populateCheckedListBox(List <String> strList, CheckedListBox box) { box.BeginUpdate(); box.Items.Clear(); foreach (String s in strList) { box.Items.Add(s); } box.EndUpdate(); }
private void RefreshUI() { Handler.BeginUpdate(); Handler.Items.Clear(); foreach (FileWatchInfo Info in WatchInfo) { Handler.Items.Add(string.Format("Filter \"{0}\" with state {1}", Info.Filter, Info.Type), Info.Enabled); } Handler.EndUpdate(); }
private void UpdateCheckedList(CheckedListBox list) { object wasSelected = list.SelectedItem; list.BeginUpdate(); for (int i = 0; i < list.Items.Count; i++) { list.SetItemChecked(i, ((Item)list.Items[i]).IsVisible); } list.SelectedItem = wasSelected; list.EndUpdate(); }
public static void Draw(CheckedListBox list) { list.BeginUpdate(); list.Items.Clear(); for (int i = 0; i < m_Filters.Count; i++) { Filter f = (Filter)m_Filters[i]; list.Items.Add(f); list.SetItemChecked(i, f.Enabled); } list.EndUpdate(); }
/// <summary> /// 绑定下拉列表控件为指定的数据字典列表 /// </summary> /// <param name="combo">下拉列表控件</param> /// <param name="itemList">数据字典列表</param> /// <param name="defaultValue">默认值</param> public static void BindDictItems(this CheckedListBox combo, List <CListItem> itemList, string defaultValue) { combo.BeginUpdate(); //可以加快 combo.Items.Clear(); combo.Items.AddRange(itemList.ToArray()); //可以加快 if (!string.IsNullOrEmpty(defaultValue)) { combo.SetComboBoxItem(defaultValue); } combo.EndUpdate();//可以加快 }
/// <summary> /// CheckedListBox控件绑定到数据源 /// </summary> /// <param name="cbx"></param> /// <param name="strValueColumn"></param> /// <param name="strDisplayColumn"></param> /// <param name="strSql"></param> /// <param name="strTableName"></param> public void CheckedListBoxBindDataSource(CheckedListBox chlb, string strValueColumn, string strDisplayColumn, string strSql, string strTableName) { try { chlb.BeginUpdate(); chlb.DataSource = dal.GetDataTable(strSql, strTableName); chlb.DisplayMember = strDisplayColumn; chlb.ValueMember = strValueColumn; chlb.EndUpdate(); } catch (Exception e) { MessageBox.Show(e.Message, "软件提示"); throw e; } }
void InitializeCheckedListBox(CheckedListBox box, CheckableSelectableListNodeList list) { box.BeginUpdate(); box.Items.Clear(); for (int i = 0; i < list.Count; i++) { CheckableSelectableListNode node = list[i]; box.Items.Add(node, node.Checked); if (node.Selected) { box.SelectedIndices.Add(i); } } box.EndUpdate(); }
public static void Fill(this CheckedListBox value, string categoryName, bool defaultCheckState) { Validation.IsNotNull(value, "value"); Validation.IsNotNullOrEmpty(categoryName, "categoryName"); value.BeginUpdate(); value.Items.Clear(); value.CheckOnClick = true; var tagSet = SystemTags.GetTagSet(categoryName); foreach (var tag in tagSet.Tags.Values) { value.Items.Add(tag, defaultCheckState); } value.EndUpdate(); }
public static void SetItems <T>(this CheckedListBox lb, T[] items, T[] checkedItems) { lb.BeginUpdate(); checkedItems = checkedItems ?? new T[0]; try { lb.Items.Clear(); lb.Items.AddRange(items.Cast <object>().ToArray()); } finally { lb.EndUpdate(); } foreach (var index in checkedItems.Select(i => Array.IndexOf(items, i))) { lb.SetItemChecked(index, true); } }
/// <summary> /// Move a selected item up or down /// </summary> /// <param name="sender"></param> /// <param name="pDirectionUp"> /// true to move up, false to move down (default is move up) /// </param> public static void MoveItem(this CheckedListBox sender, bool pDirectionUp = true) { if (sender.SelectedItem == null) { return; } sender.BeginUpdate(); try { var selectedIndex = sender.SelectedIndex; object selectedItem = sender.SelectedItem; var checkedState = sender.GetItemChecked(selectedIndex); sender.Items.RemoveAt(selectedIndex); var newIndex = selectedIndex; if (pDirectionUp) { newIndex = newIndex - 1; } else { newIndex = newIndex + 1; } if (newIndex > sender.Items.Count - 1 | newIndex < 0) { newIndex = sender.Items.Count; } sender.Items.Insert(newIndex, selectedItem); sender.SetItemChecked(newIndex, checkedState); sender.SelectedIndex = newIndex; } finally { sender.EndUpdate(); } }
private void lb_VisibleChanged(object sender, EventArgs e) { // HACK: Oh. My. God. // This was found through trial and error, and I'm NOT happy with it. // The deal is that there is a bug in the MS implementation of ListBox, such // that if you call SetSelected before the underlying window has been created, // the SetSelected call gets ignored. // So, what we do here is wait for VisibleChanged events... this is the only event // I could find that always fires after the Handle is set. But, it also fires before // the handle is set, and several times so quickly in succession that the remove // event handler code below can happen while there is an event still in the queue. // Apparently that message that is already in the queue fires this callback again, // even though it's been removed. CheckedListBox lb = (CheckedListBox)sender; if (lb.Handle == IntPtr.Zero) { return; } if (lb.Items.Count > 0) { return; } lb.VisibleChanged -= new EventHandler(lb_VisibleChanged); lb.BeginUpdate(); foreach (Option o in m_field.GetOptions()) { int i = lb.Items.Add(o); if (m_field.IsValSet(o.Val)) { //lb.SetSelected(i, true); lb.SetItemChecked(i, true); } } lb.EndUpdate(); }
// FullRefresh вызывается при изменениях SelectedProperty private void FullRefresh() { cons.Clear(); lstbox.Items.Clear(); if (SelectedObject == null) { return; } // Заполняем массив всемы событиями EventInfo[] eventInfo = SelectedObject.GetType().GetEvents(); lstbox.BeginUpdate(); // В цикле перичисляем все события foreach (EventInfo evtInfo in eventInfo) { bool bChecked = false; // Проверяем событие на предмет того, // наследует ли SelectedObject класс Control if (SelectedObject.GetType() == typeof(Control)) { bChecked = true; } // ... В противном случае проверяем, реализовано ли событие в Control else if (SelectedObject is Control) { bChecked = typeof(Control).GetEvent(evtInfo.Name) == null; } lstbox.Items.Add(evtInfo.Name, bChecked); } lstbox.EndUpdate(); }
// FullRefresh called when SelectedProperty changes. void FullRefresh() { cons.Clear(); lstbox.Items.Clear(); if (SelectedObject == null) { return; } // Fill an array with all the events. EventInfo[] aevtinfo = SelectedObject.GetType().GetEvents(); lstbox.BeginUpdate(); // Loop through the events. foreach (EventInfo evtinfo in aevtinfo) { bool bChecked = false; // Check the event if the SelectedObject is a Control. if (SelectedObject.GetType() == typeof(Control)) { bChecked = true; } // Otherwise, check if the event is not implemented by Control. else if (SelectedObject is Control) { bChecked = typeof(Control).GetEvent(evtinfo.Name) == null; } lstbox.Items.Add(evtinfo.Name, bChecked); } lstbox.EndUpdate(); }
void DisplayData() { Text = "Edit Class (" + MyAT.ClassName + " - " + MyAT.DisplayName + ")"; txtName.Text = MyAT.DisplayName; txtClassName.Text = MyAT.ClassName; cbClassType.BeginUpdate(); cbClassType.Items.Clear(); cbClassType.Items.AddRange(Enum.GetNames(MyAT.ClassType.GetType())); if (MyAT.ClassType > ~Enums.eClassType.None & MyAT.ClassType < (Enums.eClassType)cbClassType.Items.Count) { cbClassType.SelectedIndex = (int)MyAT.ClassType; } else { cbClassType.SelectedIndex = 0; } cbClassType.EndUpdate(); udColumn.Value = !(Decimal.Compare(new Decimal(MyAT.Column + 2), udColumn.Maximum) <= 0 & Decimal.Compare(new Decimal(MyAT.Column), udColumn.Minimum) >= 0) ? udColumn.Minimum : new Decimal(MyAT.Column); udThreat.Value = !(MyAT.BaseThreat > (double)Convert.ToSingle(udThreat.Maximum) | MyAT.BaseThreat < (double)Convert.ToSingle(udThreat.Minimum)) ? new Decimal(MyAT.BaseThreat) : new Decimal(0); chkPlayable.Checked = MyAT.Playable; txtHP.Text = Convert.ToString(MyAT.Hitpoints); txtHPCap.Text = Convert.ToString(MyAT.HPCap); txtResCap.Text = Convert.ToString(MyAT.ResCap * 100f); txtDamCap.Text = Convert.ToString(MyAT.DamageCap * 100f); txtRechargeCap.Text = Convert.ToString(MyAT.RechargeCap * 100f); txtRecCap.Text = Convert.ToString(MyAT.RecoveryCap * 100f); txtRegCap.Text = Convert.ToString(MyAT.RegenCap * 100f); txtBaseRec.Text = Strings.Format(MyAT.BaseRecovery, "##0" + NumberFormatInfo.CurrentInfo.NumberDecimalSeparator + "00##"); txtBaseRegen.Text = Strings.Format(MyAT.BaseRegen, "##0" + NumberFormatInfo.CurrentInfo.NumberDecimalSeparator + "00##"); txtPerceptionCap.Text = Convert.ToString(MyAT.PerceptionCap); cbPriGroup.BeginUpdate(); cbSecGroup.BeginUpdate(); cbPriGroup.Items.Clear(); cbSecGroup.Items.Clear(); foreach (string key in DatabaseAPI.Database.PowersetGroups.Keys) { cbPriGroup.Items.Add(key); cbSecGroup.Items.Add(key); } cbPriGroup.SelectedValue = MyAT.PrimaryGroup; cbSecGroup.SelectedValue = MyAT.SecondaryGroup; cbPriGroup.EndUpdate(); cbSecGroup.EndUpdate(); udColumn.Value = new Decimal(MyAT.Column); clbOrigin.BeginUpdate(); clbOrigin.Items.Clear(); foreach (Origin origin in DatabaseAPI.Database.Origins) { bool isChecked = false; int num = MyAT.Origin.Length - 1; for (int index = 0; index <= num; ++index) { if (origin.Name.ToLower() == MyAT.Origin[index].ToLower()) { isChecked = true; } } clbOrigin.Items.Add(origin.Name, isChecked); } clbOrigin.EndUpdate(); txtDescShort.Text = MyAT.DescShort; txtDescLong.Text = MyAT.DescLong; }
/// <summary> /// Overrides the method used to provide basic behaviour for selecting editor. /// Shows our custom control for editing the value. /// </summary> /// <param name="context">The context of the editing control</param> /// <param name="provider">A valid service provider</param> /// <param name="value">The current value of the object to edit</param> /// <returns>The new value of the object</returns> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (context != null && context.Instance != null && provider != null) { edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (edSvc != null) { // Create a CheckedListBox and populate it with all the enum values clb = new CheckedListBox(); clb.BorderStyle = BorderStyle.FixedSingle; clb.CheckOnClick = true; clb.MouseDown += new MouseEventHandler(this.OnMouseDown); clb.MouseMove += new MouseEventHandler(this.OnMouseMoved); clb.DoubleClick += new EventHandler(this.OnDoubleClick); tooltipControl = new ToolTip(); tooltipControl.ShowAlways = true; clb.BeginUpdate(); foreach (string name in Enum.GetNames(context.PropertyDescriptor.PropertyType)) { // Get the enum value object enumVal = Enum.Parse(context.PropertyDescriptor.PropertyType, name); // Get the int value int intVal = (int)Convert.ChangeType(enumVal, typeof(int)); // Get the description attribute for this field System.Reflection.FieldInfo fi = context.PropertyDescriptor.PropertyType.GetField(name); DescriptionAttribute[] attrs = ( DescriptionAttribute[] ) fi.GetCustomAttributes(typeof(DescriptionAttribute), false); BrowsableAttribute[] skipAttr = ( BrowsableAttribute[] ) fi.GetCustomAttributes(typeof(BrowsableAttribute), false); // if flag must be skip in desiner if (skipAttr.Length > 0 && skipAttr[0].Browsable == false) { continue; } // Store the the description string tooltip = (attrs.Length > 0) ? attrs[0].Description : string.Empty; // Get the int value of the current enum value (the one being edited) int intEdited = ( int )Convert.ChangeType(value, typeof(int)); // show in tooltip int value of flag tooltip += "(value: " + intEdited.ToString() + ")"; // Creates a clbItem that stores the name, the int value and the tooltip clbItem item = new clbItem(enumVal.ToString(), intVal, tooltip); // Get the checkstate from the value being edited bool checkedItem = (intEdited & intVal) > 0; // Add the item with the right check state clb.Items.Add(item, checkedItem); } clb.EndUpdate(); // Show our CheckedListbox as a DropDownControl. // This methods returns only when the dropdowncontrol is closed edSvc.DropDownControl(clb); // Get the sum of all checked flags int result = 0; foreach (clbItem obj in clb.CheckedItems) { result += obj.Value; } // return the right enum value corresponding to the result return(Enum.ToObject(context.PropertyDescriptor.PropertyType, result)); } } return(value); }
/// <summary> /// 打开选项列表,刷新下来菜单 /// </summary> /// <param name="e"></param> protected override void OnDropDown(EventArgs e) { if (lst.Items.Count == 0) { // 假如数据还没有加载 // 那么加载. lst.BeginUpdate(); for (int i = 0; i < this.CheckAbleItemList.Count; i++) { lst.Items.Add(this.CheckAbleItemList[i]); } lst.EndUpdate(); lst.ItemHeight = this.ItemHeight; lst.BorderStyle = BorderStyle.FixedSingle; lst.Size = new Size(this.DropDownWidth, this.ItemHeight * (this.MaxDropDownItems - 1) - (int)this.ItemHeight / 2); lst.Location = new Point(this.Left, this.Top + this.ItemHeight + 6); this.Parent.Controls.Add(lst); // 加这句话的目的, 是为了避免 控件被别的控件挡住. lst.BringToFront(); } if (lstShowFlag == CheckedListBoxShowMode.Hide) { // 当前未显示,调整为显示. lst.Show(); lst.Focus(); lstShowFlag = CheckedListBoxShowMode.Show; } else if (lstShowFlag == CheckedListBoxShowMode.Show) { // 当前已显示,调整为不显示. lst.Hide(); lstShowFlag = CheckedListBoxShowMode.Hide; } else if (lstShowFlag == CheckedListBoxShowMode.LostFocus) { // 当前是 CheckedListBox 失去输入焦点. // 对于失去焦点的情况. // 需要作判断 // 因为 可能是点到其它的控件,而 CheckedListBox 失去输入焦点. // 也可能是 直接从 CheckedListBox 点到本控件. if (DateTime.Now.AddMilliseconds(-250) > lastLostFocusDateTime) { // 如果 CheckedListBox 失去焦点的时间 // 与本次点击下拉列表的时间 // 间隔超过 250 毫秒 // 认为是 经过了另外一个控件. // 现在点击回来了,需要显示. lst.Show(); lst.Focus(); lstShowFlag = CheckedListBoxShowMode.Show; } else { // 是直接从 CheckedListBox 失去焦点 // 然后再点击了 本 ComboBox 控件. lstShowFlag = CheckedListBoxShowMode.Hide; } } }