private void Log(string message, Color color) { if (_listBox.InvokeRequired) { _listBox.BeginInvoke(new Action <string, Color>(Log), new object[] { message, color }); } else { _listBox.BeginUpdate(); _listBox.Items.Add(new Dictionary <string, object> { { "Text", message }, { "ForeColor", color } }); _listBox.TopIndex = _listBox.Items.Count - 1; _listBox.EndUpdate(); } }
protected override void OnDropDown(EventArgs e) { lst.Items.Clear(); lst.Show(); 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(); for (int i = 0; i < this.Items.Count; i++) { lst.Items.Add(this.Items[i]); } lst.EndUpdate(); this.Parent.Controls.Add(lst); }
void ListFontFamilies(ListBox listBox, string filter) { var families = fonts.Families.Select(x => x.Name).ToArray(); Array.Sort(families); listBox.BeginUpdate(); listBox1.Items.Clear(); foreach (var family in families) { if (String.IsNullOrEmpty(filter) || -1 != family.IndexOf(filter, StringComparison.CurrentCultureIgnoreCase)) { listBox.Items.Add(family); } } listBox.EndUpdate(); }
/// <summary> /// FillVariableListBox() /// ListBox and ComboBox both derive from ListControl /// According to Help file Items property of ListControl is Public. /// Contrary to helpfile there is no such property. /// So polymorphism could not be used as expected /// </summary> /// <param name="lbx">ListBox to be filled</param> /// <param name="scopeWord">The scope of the variable</param> protected void FillVariableListBox(ListBox lbx, VariableType scopeWord) { lbx.Items.Clear(); VariableCollection vars = this.EpiInterpreter.Context.MemoryRegion.GetVariablesInScope(scopeWord); lbx.BeginUpdate(); foreach (IVariable var in vars) { if (!(var is Epi.Fields.PredefinedDataField)) { lbx.Items.Add(var.Name.ToString()); } } lbx.EndUpdate(); lbx.Sorted = true; lbx.Refresh(); }
private void UpdateListBoxItem(ListBox lb, object item) { int index = lb.Items.IndexOf(item); int currentIndex = lb.SelectedIndex; lb.BeginUpdate(); try { lb.ClearSelected(); lb.Items[index] = item; lb.SelectedIndex = currentIndex; } finally { lb.EndUpdate(); } }
private void moveItems(ListBox from, ListBox to) { if (from.SelectedItems.Count == 0) { MessageBox.Show("Empty selection"); return; } object[] tmp = new object[from.SelectedItems.Count]; from.SelectedItems.CopyTo(tmp, 0); to.Items.AddRange(tmp); from.BeginUpdate(); foreach (var item in tmp) { from.Items.Remove(item); } from.EndUpdate(); }
//Mise a jour du carnet internal static void UpdateList(string fichier, ListeDeContact list, ListBox listb) { listb.BeginUpdate(); ManipFichier.Ecriture(fichier, list); listb.Items.Clear(); list.Carnet.Clear(); ManipFichier.Lecture(fichier, list); //var sortie = from s in list.Carnet // select s.LastName foreach (Contact item in list.Carnet) { listb.Items.Add(item); } listb.EndUpdate(); }
public void LoadList(string selectedItemLast) { ListBox.BeginUpdate(); ListBox.Items.Clear(); foreach (ReportSpec item in List) { string name = item.GetKey(); int i = ListBox.Items.Add(name); // Select the previous selection if it is seen. if (ListBox.Items[i].ToString() == selectedItemLast) { ListBox.SelectedIndex = i; } } ListBox.EndUpdate(); }
private void ReplaceContents(object[] nodes) { /* an attempt to prevent the control from jerking */ object selection = treeListBox.Items[treeListBox.SelectedIndex]; int topIndex = treeListBox.TopIndex; int leftEdge = GetScrollPos(treeListBox.Handle, 0); treeListBox.BeginUpdate(); treeListBox.Items.Clear(); treeListBox.Items.AddRange(nodes); treeListBox.SelectedItem = selection; treeListBox.TopIndex = topIndex; treeListBox.EndUpdate(); /* send WM_HSCROLL message to the list box */ SendMessage(treeListBox.Handle, 0x0114, 4 + (leftEdge << 16), 0); }
/// <summary> /// this were we can make suggestions /// </summary> /// <param name="e"></param> protected override void OnTextChanged(EventArgs e) { base.OnTextChanged(e); if (!m_fromKeyboard || !Focused) { return; } m_suggestionList.BeginUpdate(); m_suggestionList.Items.Clear(); StringMatcher matcher = new StringMatcher(MatchingMethod, Text); foreach (object item in Items) { StringMatch sm = matcher.Match(GetItemText(item)); if (sm != null) { m_suggestionList.Items.Add(sm); } } m_suggestionList.EndUpdate(); bool visible = m_suggestionList.Items.Count != 0; if (m_suggestionList.Items.Count == 1 && ((StringMatch)m_suggestionList.Items[0]).Text.Length == Text.Trim().Length) { StringMatch sel = (StringMatch)m_suggestionList.Items[0]; Text = sel.Text; Select(0, Text.Length); visible = false; } if (visible) { showDropDown(); } else { hideDropDown(); } m_fromKeyboard = false; }
/// <summary> /// ListBox控件绑定到数据源 /// </summary> /// <param name="cbx"></param> /// <param name="strValueColumn"></param> /// <param name="strDisplayColumn"></param> /// <param name="strSql"></param> /// <param name="strTableName"></param> public void ListBoxBindDataSource(ListBox lbx, string strValueColumn, string strDisplayColumn, string strSql, string strTableName) { DataOperate dataOper = new DataOperate(); try { lbx.BeginUpdate(); lbx.DataSource = dataOper.GetDataTable(strSql, strTableName); lbx.DisplayMember = strDisplayColumn; lbx.ValueMember = strValueColumn; lbx.EndUpdate(); } catch (Exception e) { MessageBox.Show(e.Message, "软件提示"); throw e; } }
private void Form1_Load(object sender, EventArgs e) { myListbox.Size = new System.Drawing.Size(200, 100); myListbox.Location = new System.Drawing.Point(10, 10); myListbox.SelectedIndexChanged += new EventHandler(myListBox_SelectedIndexChanged); this.Controls.Add(myListbox); myListbox.MultiColumn = true; myListbox.SelectionMode = SelectionMode.MultiExtended; myListbox.BeginUpdate(); for (int x = 1; x <= 100; x++) { myListbox.Items.Add("Eleman " + x.ToString()); } myListbox.EndUpdate(); //myListbox.SetSelected(1, true); //myListbox.SetSelected(2, true); //myListbox.SetSelected(4, true); }
private void MoveSelectedItems(ListBox list1, ListBox list2) { list2.BeginUpdate(); //Начало обновления списка List2 foreach (object item in list1.SelectedItems) { //Добавление элемента из списка List1 в состав списка List2 list2.Items.Add(item); } list2.EndUpdate(); //Окончание обновления списка List2 //Запоминание индексов выделенных элементов в списке List1 ListBox.SelectedIndexCollection indeces = list1.SelectedIndices; list1.BeginUpdate(); //Начало обновления списка List1 for (int i = indeces.Count - 1; i >= 0; i--) { list1.Items.RemoveAt(indeces[i]); //Удаление из списка List1, выделенных //элементов } list1.EndUpdate(); //Окончание обновления списка List1 }
public void Visit(TestCaseResult result) { if (result.Executed) { if (result.IsFailure) { TestResultItem item = new TestResultItem(result); //string resultString = String.Format("{0}:{1}", result.Name, result.Message); testDetails.BeginUpdate(); testDetails.Items.Insert(testDetails.Items.Count, item); testDetails.EndUpdate(); } } else { notRunTree.Nodes.Add(MakeNotRunNode(result)); } }
/// <summary> /// removes item from list box /// </summary> /// <param name="obj"></param> /// <param name="text"></param> private void RemoveListBox(ListBox obj, string text) { if (obj.InvokeRequired) { RemoveListBoxCallback tcb = new RemoveListBoxCallback(RemoveListBox); this.Invoke(tcb, new Object[] { obj, text }); } else { if (!obj.Items.Contains(text)) { return; } obj.BeginUpdate(); obj.Items.Remove(text); obj.EndUpdate(); } }
private void shuffleListBox(ListBox listbox) { ListBox.ObjectCollection list = listbox.Items; Random rng = new Random(); int n = list.Count; listbox.BeginUpdate(); while (n > 1) { n--; int k = rng.Next(n + 1); object value = list[k]; list[k] = list[n]; list[n] = value; } listbox.EndUpdate(); listbox.Invalidate(); }
private void UpdateListBoxItem(ListBox lb, object item) { //int index; /* * if (lb.InvokeRequired) * { * lb.BeginInvoke(new MethodInvoker(new MethodInvoker(delegate * { * index = lb.items.IndexOf(item); * }))); * } * else * { * l.Items.Add(s); * } * */ try { if (lb.InvokeRequired) { object[] paramList = new object[2]; paramList[0] = lb; paramList[1] = item; lb.Invoke(new updateList2(UpdateListBoxItem2), (object)paramList); } else { int index = lb.Items.IndexOf(item); //int currIndex = lb.SelectedIndex; lb.BeginUpdate(); lb.ClearSelected(); lb.Items[index] = (string)item + ": Has been zipped!"; //lb.SelectedIndex = currIndex; } } finally { lb.EndUpdate(); } }
private void UpdateListBox() { if (this.Text != _formerValue) { _formerValue = this.Text; String word = GetWord(); if (word.Length > 0) { String[] matches = Array.FindAll(this.Values, x => (x.Contains(word))); if (matches.Length > 0) { _listBox.BeginUpdate(); _listBox.Items.Clear(); _listBox.Items.AddRange(matches); _listBox.SelectedIndex = 0; int height = 0; using (Graphics graphics = _listBox.CreateGraphics()) { for (int i = 0; i < _listBox.Items.Count; i++) { height += _listBox.GetItemHeight(i); if (height > 200) { break; } } } _listBox.Height = Math.Min(height, 200); _listBox.EndUpdate(); ShowListBox(); this.Focus(); } else { ResetListBox(); } } else { ResetListBox(); } } }
/// <summary>Expands whole tree of items starting at this item.</summary> public void ExpandAll() { if (_items.Count == 0) { return; } bool p = IsPresented; bool hasListBox = IsAttachedToListBox; if (hasListBox && p) { ListBox.BeginUpdate(); } _expand_all(this); if (hasListBox && p) { ListBox.EndUpdate(); } }
/// <summary> /// Remove selected items in a ListBox control. /// </summary> /// <param name="listBox"></param> public static void RemoveListBoxItems(ListBox listBox) { switch (listBox.SelectionMode) { case SelectionMode.MultiExtended: { // in order to remove items, we must remove items by order, descendly. ListBox.SelectedIndexCollection ic = listBox.SelectedIndices; int[] indices = new int[ic.Count]; for (int i = 0; i < ic.Count; i++) { indices[i] = ic[i]; } Array.Sort(indices); Array.Reverse(indices); listBox.BeginUpdate(); for (int i = 0; i < indices.Length; i++) { int idx = indices[i]; object val = listBox.Items[idx]; listBox.Items.Remove(val); } listBox.EndUpdate(); listBox.SelectedIndex = -1; } break; case SelectionMode.MultiSimple: throw new NotImplementedException("MultiSimple not yet implemented."); //break; case SelectionMode.One: listBox.Items.RemoveAt(listBox.SelectedIndex); break; default: throw new ArgumentOutOfRangeException(listBox.SelectionMode.ToString()); } }
public static void AltLoadListBox(ListBox ddl, DataTable dt) { try { ddl.BeginUpdate(); for (var i = 0; i < dt.Rows.Count; i++) { if (dt.Rows[i][0].ToString().Length > 0) { ddl.Items.Add(dt.Rows[i][0].ToString()); } } ddl.EndUpdate(); } catch (Exception ex) { MessageClass.ShowError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name); } }
private void MoveComponent(ListBox source, ListBox dest, IEnumerable <DeckManager.Components.BaseComponent> items) { source.BeginUpdate(); dest.BeginUpdate(); source.Items.Remove(items); dest.Items.AddRange(items.ToArray()); // probably a better way to get the nodenames but whatever DeckManager.Boards.Dradis.DradisNodeName SourceNode; _sectors.TryGetValue(source, out SourceNode); DeckManager.Boards.Dradis.DradisNodeName DestNode; _sectors.TryGetValue(dest, out DestNode); Program.GManager.MoveComponents(SourceNode, DestNode, items); source.EndUpdate(); dest.EndUpdate(); // todo add rollback on error checking? }
public Form1() { this.SuspendLayout(); this.AutoSize = true; // this.Size = new Size(200, 150); button1 = new Button(); button1.Size = new Size(60, 30); button1.Location = new Point(20, 20); button1.Text = "Click me"; this.Controls.Add(button1); button1.Click += new EventHandler(button1_Click); listBox1 = new ListBox(); listBox1.Size = new System.Drawing.Size(200, 100); listBox1.Location = new System.Drawing.Point(20, 60); this.Controls.Add(listBox1); listBox1.MultiColumn = true; // true=複数選択可能 listBox1.SelectionMode = SelectionMode.MultiExtended; // SelectionMode.MultiExtended = 横スクロール可 listBox1.BeginUpdate(); for (int x = 1; x <= 10; x++) { listBox1.Items.Add("Item " + x.ToString()); } listBox1.EndUpdate(); listBox1.SetSelected(1, true); // Item1,3,5(2,4,6番目)を選択状態に listBox1.SetSelected(3, true); listBox1.SetSelected(5, true); listBox2 = new ListBox(); listBox2.Size = new Size(200, 100); listBox2.Location = new Point(300, 60); this.Controls.Add(listBox2); listBox2.BeginUpdate(); for (int x = 1; x <= 10; x++) { listBox2.Items.Add("Item " + x.ToString()); } listBox2.EndUpdate(); this.ResumeLayout(false); this.listBox1.SelectedIndexChanged += new EventHandler(listBox1_SelectedIndexChanged); }
/// <summary> /// Search for a string in an array of string, and add every instance to a specified listbox. /// Each item in the listbox will be tagged with the respective index; /// </summary> /// <param name="names">The list of names to search.</param> /// <param name="name">The string to search for.</param> /// <param name="listBox">The listbox to write to.</param> /// <param name="ignoreCase">Specifies whether to ignore case when searching.</param> public static void Search(ComboBox.ObjectCollection names, string name, ListBox listBox, bool ignoreCase) { listBox.BeginUpdate(); listBox.Items.Clear(); if (name == "") { listBox.EndUpdate(); return; } for (int i = 0; i < names.Count; i++) { if (((string)names[i]).IndexOf(name, StringComparison.CurrentCultureIgnoreCase) >= 0) { listBox.Items.Add(names[i]); } } listBox.EndUpdate(); listBox.BringToFront(); }
private void update_list(ListBox list) { if (LoadedLog.columns == null) { return; } list.ClearSelected(); list.BeginUpdate(); list.Items.Clear(); string[] columns = LoadedLog.columns; foreach (string col in columns) { list.Items.Add(col); } list.EndUpdate(); list.Refresh(); }
public PrintWordSelection(VocabularyBook book) { InitializeComponent(); Icon = Icon.FromHandle(Icons.Print.GetHicon()); this.book = book; ListBox.BeginUpdate(); foreach (var word in book.Words) { ListBox.Items.Add($"{word.MotherTongue} - {word.ForeignLangText}", true); } ListBox.EndUpdate(); CbUnpracticed.Enabled = book.Statistics.Unpracticed > 0; CbWronglyPracticed.Enabled = book.Statistics.WronglyPracticed > 0; CbCorrectlyPracticed.Enabled = book.Statistics.CorrectlyPracticed > 0; CbFullyPracticed.Enabled = book.Statistics.FullyPracticed > 0; }
private void buttonAddFiles_Click(object sender, EventArgs e) { openFileDialog.Filter = "htm files (*.htm)|*.htm"; openFileDialog.FilterIndex = 2; if (openFileDialog.ShowDialog() == DialogResult.OK) { listBoxFiles.BeginUpdate(); for (int i = 0; i < openFileDialog.FileNames.Length; i++) { string fileName = openFileDialog.FileNames[i]; if (!listBoxFiles.Items.Contains(fileName)) { listBoxFiles.Items.Add(openFileDialog.FileNames[i]); } } listBoxFiles.EndUpdate(); } }
/// <summary>Collapses whole tree of items starting at this item.</summary> public void CollapseAll() { if (Items.Count == 0) { return; } bool p = IsPresented; bool hasListBox = IsAttachedToListBox; if (hasListBox && p) { ListBox.BeginUpdate(); } _collapse_all(this); if (hasListBox && p) { ListBox.EndUpdate(); } }
void InitializeListBox(ListBox box, SelectableListNodeList list) { box.BeginUpdate(); box.Items.Clear(); for (int i = 0; i < list.Count; i++) { SelectableListNode node = list[i]; box.Items.Add(node); if (node.Selected) { box.SelectedIndices.Add(i); } } box.EndUpdate(); }
private void LbCommands_MouseMove(object sender, MouseEventArgs e) { count = Math.Max(1, lbCommands.IndexFromPoint(e.Location) + 1); if (lastIndex != count) { int topIndex = Math.Max(0, Math.Min(lbCommands.TopIndex + e.Delta, lbCommands.Items.Count - 1)); lbCommands.BeginUpdate(); lbCommands.ClearSelected(); for (int i = 0; i < count; ++i) { lbCommands.SelectedIndex = i; } lblUndoRedoCount.Text = cmdTypeText + " " + count + " command(s)"; lastIndex = count; lbCommands.EndUpdate(); lbCommands.TopIndex = topIndex; } }
public static void editIlasm(ListBox lb) { //shows a dialog for the user to edit il code then sticks modified il in listbox editIlDialog ed = new editIlDialog(); StringBuilder sb = new StringBuilder(); bool first = true; foreach(object o in lb.Items) { if (first == true) { first = false; } else { sb.Append("\r\n"); } sb.Append(o.ToString()); } ed.il = sb.ToString(); if (ed.ShowDialog() == DialogResult.OK) { string[] str = ed.il.Split("\n".ToCharArray()); lb.BeginUpdate(); lb.Items.Clear(); foreach (string s in str) { lb.Items.Add(s.Trim()); } lb.EndUpdate(); } }
private void InitializeComponent() { Text = "LayoutDemo"; AutoScaleBaseSize = new Size(5, 13); MinimumSize = new Size(280, 305); ClientSize = new Size(392, 342); inputBox = new TextBox(); inputBox.Location = new Point(16, 24); inputBox.Text = "Windows Forms Layout Demo"; inputBox.TabIndex = 0; inputBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; inputBox.Size = new Size(360, 20); Controls.Add(inputBox); listBox = new ListBox(); listBox.Location = new Point(16, 60); listBox.Size = new Size(250, 100); listBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; listBox.BeginUpdate(); for (int i = 1; i <= 20; i++) { listBox.Items.Add("Item " + i.ToString()); } listBox.EndUpdate(); listBox.SelectedIndex = 0; Controls.Add(listBox); logo = new PictureBox(); logo.Image = Image.FromFile("xml11_tiny.jpg"); logo.Location = new Point(282, 60); logo.Anchor = AnchorStyles.Top | AnchorStyles.Right; Controls.Add(logo); textBox = new TextBox(); textBox.Location = new Point(16, 174); textBox.Multiline = true; textBox.ScrollBars = ScrollBars.Vertical; textBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom; textBox.Size = new Size(360, 100); Controls.Add(textBox); buttonDump = new Button(); buttonDump.Size = new Size(60, 30); buttonDump.TabIndex = 1; buttonDump.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonDump.Location = new Point(164, 296); buttonDump.Text = "Dump"; buttonDump.Click += new EventHandler(ClickDump); Controls.Add(buttonDump); buttonClear = new Button(); buttonClear.Size = new Size(60, 30); buttonClear.TabIndex = 1; buttonClear.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonClear.Location = new Point(240, 296); buttonClear.Text = "Clear"; buttonClear.Click += new EventHandler(ClickClear); Controls.Add(buttonClear); buttonExit = new Button(); buttonExit.Size = new Size(60, 30); buttonExit.TabIndex = 1; buttonExit.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonExit.Location = new Point(316, 296); buttonExit.Text = "Exit"; buttonExit.Click += new EventHandler(ClickExit); Controls.Add(buttonExit); }