public static string DealWithCheckListSave(CheckedListBox chkList) { string strCollected = string.Empty; for (int i = 0; i < chkList.Items.Count; i++) { if (chkList.GetItemChecked(i)) { if (strCollected == string.Empty) { strCollected = chkList.GetItemText( chkList.Items[i]); } else { strCollected = strCollected + "+" + chkList. GetItemText(chkList.Items[i]); } } } return(strCollected); }
// 返回选择框中被选中的记录 public string[] SelectedStrs(CheckedListBox CLB) { int SelectedNum = 0; for (int i = 0; i < CLB.Items.Count; i++) { if (CLB.GetItemChecked(i)) { SelectedNum++; } } //MessageBox.Show(SelectedNum.ToString()); if (SelectedNum == 0) { return(null); } else { string[] Cores = new string[SelectedNum]; int j = 0; for (int i = 0; i < CLB.Items.Count; i++) { if (CLB.GetItemChecked(i)) { Cores[j] = CLB.GetItemText(CLB.Items[i]); //MessageBox.Show(Cores[j]); j++; CLB.SetItemCheckState(i, CheckState.Unchecked); } } return(Cores); } }
private IEnumerable <string> GetCheckedText() { foreach (int number in CheckedListBox.SelectedIndices) { yield return(CheckedListBox.GetItemText(number)); } }
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value) { try { IWindowsFormsEditorService svc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (svc != null) { if (value is string) { CheckedListBox clb = new CheckedListBox(); clb.ItemCheck += (object sender, ItemCheckEventArgs e) => { for (int i = 0; i < clb.Items.Count; i++) { if (i != e.Index) { clb.SetItemCheckState(i, System.Windows.Forms.CheckState.Unchecked); } } }; foreach (var s in GlobalGeometryObject.SurfacePartList) { clb.Items.Add(s); } clb.BorderStyle = BorderStyle.None; string partName = value as string; for (int i = 0; i < clb.Items.Count; i++) { clb.SetItemChecked(i, clb.GetItemText(clb.Items[i]) == partName); } svc.DropDownControl(clb); if (clb.SelectedItem != null) { partName = clb.GetItemText(clb.SelectedItem); } return(partName); } } } catch (Exception ex) { return(value); } return(value); }
/// <summary> /// 获得选中项的文本Text /// </summary> /// <param name="cblItems"></param> /// <returns></returns> public static string GetCheckedItemsValue(CheckedListBox cblItems) { string resultList = ""; for (int i = 0; i < cblItems.CheckedItems.Count; i++) { resultList += string.Format("{0},", cblItems.GetItemText(cblItems.CheckedItems[i])); } return(resultList.Trim(',')); }
/// <summary> /// (GetText):获取获取已选的文本 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private string GetText(CheckedListBox chklb) { string checkedText = string.Empty; for (int i = 0; i < chklb.CheckedItems.Count; i++) { checkedText += (String.IsNullOrEmpty(checkedText) ? "" : ",") + chklb.GetItemText(chklb.Items[i]); } //this.DisplayText.Text = checkedText; return(checkedText); }
private void SetlboxChk(CheckedListBox lsb, string str) { for (int i = 0; i < lsb.Items.Count; i++) { string strid = lsb.GetItemText(lsb.Items[i]); if (strid == str) { lsb.SetItemChecked(i, true); } } }
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value) { try { IWindowsFormsEditorService svc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (svc != null) { if (value is List <string> ) { CheckedListBox clb = new CheckedListBox(); foreach (var s in GlobalGeometryObject.SurfacePartList) { clb.Items.Add(s); } clb.BorderStyle = BorderStyle.None; List <string> partNames = value as List <string>; for (int i = 0; i < clb.Items.Count; i++) { clb.SetItemChecked(i, partNames.Contains(clb.GetItemText(clb.Items[i]))); } svc.DropDownControl(clb); partNames.Clear(); for (int i = 0; i < clb.Items.Count; i++) { if (clb.GetItemChecked(i)) { partNames.Add(clb.GetItemText(clb.Items[i])); } } return(partNames); } } } catch (Exception ex) { return(value); } return(value); }
public static string GetCheckedItems(CheckedListBox cblItems) { string str = ""; for (int i = 0; i < cblItems.CheckedItems.Count; i++) { if (cblItems.GetItemChecked(i)) { str = str + string.Format("{0},", cblItems.GetItemText(cblItems.Items[i])); } } return(str.Trim(new char[] { ',' })); }
public static void SetCheck(CheckedListBox cblItems, string valueList) { foreach (string str in valueList.Split(new char[] { ',' })) { for (int i = 0; i < cblItems.Items.Count; i++) { if (cblItems.GetItemText(cblItems.Items[i]) == str) { cblItems.SetItemChecked(i, true); } } } }
private string gen_bits_code(CheckedListBox checkedListBox) { string code = ""; for (int i = 0; i < checkedListBox.Items.Count; i++) { if (checkedListBox.GetItemChecked(i) == true) { code += (String.IsNullOrEmpty(code) ? "" : " | ") + checkedListBox.GetItemText(checkedListBox.Items[i]); } } return(code); }
public static List <string> GetChecked(CheckedListBox checkedlistbox) { var list = new List <string>(); for (var i = 0; i < checkedlistbox.Items.Count; i++) { if (checkedlistbox.GetItemChecked(i)) { list.Add(checkedlistbox.GetItemText(checkedlistbox.Items[i])); } } return(list); }
private List <string> GetCheckedItems(CheckedListBox listBox) { var list = new List <string>(); for (int i = 0, total = listBox.Items.Count; i < total; i++) { if (listBox.GetItemChecked(i)) { list.Add(listBox.GetItemText(listBox.Items[i])); } } return(list); }
/// <summary> /// 更新通道 /// </summary> private void UpdateChannels(CheckedListBox clb, List <int> chn) { chn.Clear(); //读取被选中的通道 for (int i = 0; i < clb.Items.Count; i++) { if (clb.GetItemChecked(i)) { string itemText = clb.GetItemText(clb.Items[i]);; chn.Add(int.Parse(itemText.Substring(2))); } } }
/// <summary> /// 设置选择项 /// </summary> public void SetSelectValue(List <string> listSelect) { for (int i = 0; i < checkListBox.Items.Count; i++) { checkListBox.SetItemChecked(i, false); } ClearSelectValue(); if (listSelect == null || listSelect.Count == 0) { return; } string temp = ""; for (int i = 0; i < checkListBox.Items.Count; i++) { temp = checkListBox.GetItemText(checkListBox.Items[i]); if (listSelect.Contains(temp)) { checkListBox.SetItemChecked(i, true); } } }
public static void SetCheck(CheckedListBox cblItems, string valueList) { string[] strtemp = valueList.Split(','); foreach (string str in strtemp) { for (int i = 0; i < cblItems.Items.Count; i++) { if (cblItems.GetItemText(cblItems.Items[i]) == str) { cblItems.SetItemChecked(i, true); } } } }
/// <summary> /// 合并选中的项 /// </summary> public void CombinCheckItem() { if (_KeyWordCheckedListBox.CheckedIndices.Count <= 1) { return; } string szSource = String.Empty; foreach (var obj in _KeyWordCheckedListBox.CheckedItems) { szSource += _KeyWordCheckedListBox.GetItemText(obj) + ","; } szSource = szSource.Remove(szSource.Length - 1); EditCheckedItem form = new EditCheckedItem(WordManager, EditFormType.CombinItem, szSource); if (form.ShowDialog() == DialogResult.OK) { if (string.IsNullOrEmpty(form.ResultString)) { return; } List <string> checkItem = GetCheckedItem(_KeyWordCheckedListBox); int index = _KeyWordCheckedListBox.CheckedIndices[0]; //得到第一个选中的索引 string szFirst = _KeyWordCheckedListBox.Items[index].ToString(); //老的词 _KeyWordCheckedListBox.Items[index] = form.ResultString; //合并的结果给第一个赋值 if (checkItem.Contains(szFirst)) //过滤掉老的词,其他的删除 { checkItem.Remove(szFirst); if (CurrentWordLib.ContainsKey(szFirst)) { CurrentWordLib.Remove(szFirst); //删除旧的词 CurrentWordLib.Add(form.ResultString, POWER); //将新词加上来 } } foreach (var item in checkItem) { _KeyWordCheckedListBox.Items.Remove(item); if (CurrentWordLib.ContainsKey(item.ToString())) { CurrentWordLib.Remove(item.ToString()); //将合并前的词删除 } } } }
private void ClbSType_ItemCheck(object sender, ItemCheckEventArgs e) { CheckedListBox clb = (CheckedListBox)sender; if (e.NewValue == CheckState.Unchecked && clb.SelectedIndex == e.Index) { e.NewValue = CheckState.Checked; return; } if (ignoreCheck) { ignoreCheck = false; return; } ignoreCheck = true; GetVersions(clb.GetItemText(clb.Items[e.Index])); /* * if (e.NewValue == CheckState.Checked) * { * if (e.Index == 0) * { * clb.SetItemChecked(1, false); * GetVersions("Vanilla"); * } * else * { * clb.SetItemChecked(0, false); * GetVersions("Spigot"); * * * } * } * */ if (e.NewValue == CheckState.Checked) { for (int i = 0; i < clb.Items.Count; i++) { if (i != e.Index) { clb.SetItemChecked(i, false); } } } }
public void createColumnsFromCheckListItem() { dataGridView1.AutoGenerateColumns = false; dataGridView1.Columns.Clear(); for (int i = 0; i < checkedListBox1.Items.Count; i++) { if (checkedListBox1.GetItemChecked(i) == true) { string sField = checkedListBox1.GetItemText(checkedListBox1.Items[i]); dataGridView1.Columns.Add(sField, sField); dataGridView1.Columns[dataGridView1.Columns.Count - 1].DataPropertyName = sField; } } }
/// <summary> /// 如果值列表中有的,根据内容勾选CheckedListBox的成员 /// </summary> /// <param name="cblItems">CheckedListBox控件</param> /// <param name="valueList">逗号分隔的值列表</param> public static void SetCheck(CheckedListBox cblItems, string valueList) { string[] strtemp = valueList.Split(','); foreach (string str in strtemp) { for (int i = 0; i < cblItems.Items.Count; i++) { if (cblItems.GetItemText(cblItems.Items[i]) == str) { cblItems.SetItemChecked(i, true); //CheckBox checkBox=cblItems.Items[i] as CheckBox; //checkBox.ForeColor = System.Drawing.Color.Red; } } } }
/// <summary> /// 验证数据 /// </summary> /// <param name="_dic"></param> /// <param name="ckl"></param> public static Dictionary <int, string> Vali(CheckedListBox ckl, bool isTrue) { Dictionary <int, string> _dic = new Dictionary <int, string>(); if (!isTrue) { return(_dic); } for (int i = 0; i < ckl.Items.Count; i++) { if (ckl.GetItemChecked(i)) { _dic.Add(i, ckl.GetItemText(ckl.Items[i])); } } return(_dic); }
private void CheckCheckedListBox(CheckedListBox checkedListBox) { if (IsTruncationDiabled(checkedListBox)) { return; } foreach (var value in checkedListBox.Items) { var size = CalculateTextSize(checkedListBox, checkedListBox.GetItemText(value), +GetSystemMetrics(SM_CXMENUCHECK) + 2 * GetSystemMetrics(SM_CXBORDER)); if (size.Width > checkedListBox.Width) { ProcessTruncation(checkedListBox, size); break; } } }
private void SaveValues(Excel.Worksheet thisSheet, CheckedListBox thisList, string propname) { if (thisList.CheckedItems.Count == 0) { return; } System.Text.StringBuilder strvals = new System.Text.StringBuilder(); System.Xml.XmlWriter xvals = System.Xml.XmlWriter.Create(strvals); xvals.WriteStartElement(propname); foreach (var s in thisList.CheckedItems) { xvals.WriteElementString("Item", thisList.GetItemText(s)); } xvals.WriteEndElement(); xvals.Close(); Utilities.ExcelHelpers.addWorksheetCustomProperty(thisSheet, propname, strvals.ToString()); }
private void GetSpecificVerifyMember(CheckedListBox chckLst) { if (SpecificType == null) { ArrayList selectedMems = new ArrayList(); for (int i = 0; i < chckLst.Items.Count; i++) { if (chckLst.GetItemChecked(i)) { selectedMems.Add(chckLst.GetItemText(chckLst.Items[i])); } } if (selectedMems.Count == 2) { SpecificType = (string)selectedMems[0]; SpecificMember = (string)selectedMems[1]; SpecificMember = SpecificMember.Trim(); } } SetSimpleVerification(SpecificType, SpecificMember, chckLst); }
private void RestoreValues(Excel.Worksheet thisSheet, CheckedListBox thisList, string propname) { string vals = Utilities.ExcelHelpers.getWorksheetCustomProperty(thisSheet, propname); if (vals != null) { System.Xml.XmlReader xvals = System.Xml.XmlReader.Create(new System.IO.StringReader(vals)); while (xvals.Read()) { if (xvals.NodeType == System.Xml.XmlNodeType.Text) { for (int i = 0; i < thisList.Items.Count; i++) { if (thisList.GetItemText(thisList.Items[i]) == xvals.Value) { thisList.SetItemChecked(i, true); } } } } } }
/// <summary> /// 获取选中项的文本 /// </summary> /// <param name="item"></param> /// <returns></returns> public string GetItemText(object item) { return(checkListBox.GetItemText(item)); }
public static string ShowDialog(IWin32Window window) { Form prompt = new Form() { Width = 500, Height = 50, FormBorderStyle = FormBorderStyle.FixedDialog, Text = "Add ROM Folder", StartPosition = FormStartPosition.CenterScreen, MinimizeBox = false, MaximizeBox = false }; var consoleNameLabel = new Label() { Left = 18, Top = 20, Text = "Select Console" }; var consoleSelector = new ComboBox() { Left = 20, Top = 40, Width = 150, DropDownStyle = ComboBoxStyle.DropDownList }; consoleSelector.Items.AddRange(Form1._consoleController.GetAllConsoles().Select(x => x.Name).ToArray()); var romFolderLabel = new Label() { Left = 18, Top = 80, Text = "Select ROM Folder" }; var romFolderSelector = new CheckedListBox { Left = 20, Top = 100, Width = 440 }; consoleSelector.SelectedIndexChanged += (sender, e) => { selectedConsole = Form1._consoleController.GetAllConsoles().First(x => x.Name == consoleSelector.Text); var romFolders = Form1._romFolderController.GetRomFoldersForConsole(selectedConsole).Select(x => x.Path).ToArray(); romFolderSelector.Items.Clear(); romFolderSelector.Items.AddRange(romFolders); var height = 15; if (romFolderSelector.Items.Count > 0) { height = romFolderSelector.GetItemRectangle(0).Height *romFolderSelector.Items.Count; } romFolderSelector.ClientSize = new Size(romFolderSelector.ClientSize.Width, height); prompt.Height = romFolderSelector.Height + 180; }; if (Form1.ActiveConsole != null) { consoleSelector.SelectedItem = consoleSelector.Items[consoleSelector.Items.IndexOf(Form1.ActiveConsole.Name)]; } var deleteButton = new Button() { Text = "Delete Selected", Left = 300, Width = 100, Top = prompt.Height - 70 }; deleteButton.Click += (sender, e) => { if (selectedConsole == null) { ShowError(consoleSelector, "Please select a Console"); return; } var romFolders = new List <Data.CuratorDataSet.RomFolderRow>(); foreach (var item in romFolderSelector.CheckedItems) { var path = romFolderSelector.GetItemText(item); romFolders.Add(Form1._romFolderController.GetRomFoldersForConsole(selectedConsole).FirstOrDefault(x => x.Path == path)); } if (romFolders.Count > 0) { var confirm = MetroMessageBox.Show(window, "Are you sure you want to delete these ROM Folders?", "ROM Folder Deletion", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (confirm == DialogResult.OK) { foreach (var romFolder in romFolders) { Form1._romFolderController.Remove(romFolder); } prompt.DialogResult = confirm; } } }; Button cancelButton = new Button() { Text = "Cancel", Left = 410, Width = 50, Top = prompt.Height - 70 }; prompt.ClientSizeChanged += (sender, e) => { cancelButton.Top = prompt.Height - 70; deleteButton.Top = prompt.Height - 70; }; prompt.Controls.Add(consoleSelector); prompt.Controls.Add(deleteButton); prompt.Controls.Add(cancelButton); prompt.Controls.Add(consoleNameLabel); prompt.Controls.Add(romFolderSelector); prompt.Controls.Add(romFolderLabel); prompt.AcceptButton = deleteButton; prompt.CancelButton = cancelButton; return(prompt.ShowDialog() == DialogResult.OK ? consoleSelector.Text : string.Empty); }
public static DialogResult ShowDialog(IWin32Window window) { Form prompt = new Form() { Width = 220, Height = 200, FormBorderStyle = FormBorderStyle.FixedDialog, Text = "Add Filter", StartPosition = FormStartPosition.CenterScreen, MinimizeBox = false, MaximizeBox = false }; Label consoleNameLabel = new Label() { Left = 18, Top = 20, Text = "Select Console" }; var consoleSelector = new ComboBox() { Left = 20, Top = 40, Width = 150 }; consoleSelector.Items.AddRange(Form1._consoleController.GetAllConsoles().Select(x => x.Name).ToArray()); consoleSelector.DropDownStyle = ComboBoxStyle.DropDownList; var fileExtensionChecklist = new CheckedListBox { Left = 20, Top = 103, Height = 30 }; var filterLabel = new Label { Left = 18, Top = 80, Width = 200, Text = "File Extensions:" }; consoleSelector.SelectedIndexChanged += (sender, e) => { selectedConsole = Form1._consoleController.GetAllConsoles().Where(x => x.Name == consoleSelector.Text).FirstOrDefault(); var roms = Form1._romController.GetRomsForConsole(selectedConsole, filtered: false); var extensions = roms.Select(x => x.Extension).Distinct().ToList(); fileExtensionChecklist.Items.Clear(); fileExtensionChecklist.Items.AddRange(extensions.ToArray()); var height = 15; if (fileExtensionChecklist.Items.Count > 0) { height = fileExtensionChecklist.GetItemRectangle(0).Height *fileExtensionChecklist.Items.Count; } fileExtensionChecklist.ClientSize = new Size(fileExtensionChecklist.ClientSize.Width, height); prompt.Height = (fileExtensionChecklist.Items.Count * 15) + 200; }; consoleSelector.SelectedIndexChanged += (sender, e) => { for (var i = 0; i < fileExtensionChecklist.Items.Count; i++) { if (!string.IsNullOrWhiteSpace(selectedConsole.Filter)) { if (selectedConsole.Filter.Contains(fileExtensionChecklist.GetItemText(fileExtensionChecklist.Items[i]))) { fileExtensionChecklist.SetItemChecked(i, true); } continue; } fileExtensionChecklist.SetItemChecked(i, true); } }; if (Form1.ActiveConsole != null) { consoleSelector.SelectedItem = consoleSelector.Items[consoleSelector.Items.IndexOf(Form1.ActiveConsole.Name)]; } Button saveFilterButton = new Button() { Text = "Save Filter", Left = 20, Width = 100, Top = prompt.Height - 70 }; saveFilterButton.Click += (sender, e) => { var error = false; if (fileExtensionChecklist.CheckedItems.Count == 0) { ShowError(fileExtensionChecklist, "At least 1 extension must be allowed"); error = true; } if (string.IsNullOrWhiteSpace(consoleSelector.Text)) { ShowError(consoleSelector, "Please select a Console"); error = true; } if (error) { return; } string fileExtensions = ""; foreach (var item in fileExtensionChecklist.CheckedItems) { fileExtensions += fileExtensionChecklist.GetItemText(item) + ','; } fileExtensions = fileExtensions.TrimEnd(','); Form1._consoleController.SaveFilterForConsole(selectedConsole, fileExtensions); prompt.DialogResult = DialogResult.OK; return; }; Button cancelButton = new Button() { Text = "Cancel", Left = 130, Width = 50, Top = prompt.Height - 70, DialogResult = DialogResult.Cancel }; prompt.ClientSizeChanged += (sender, e) => { cancelButton.Top = prompt.Height - 70; saveFilterButton.Top = prompt.Height - 70; }; prompt.Controls.Add(consoleSelector); prompt.Controls.Add(saveFilterButton); prompt.Controls.Add(cancelButton); prompt.Controls.Add(consoleNameLabel); prompt.Controls.Add(filterLabel); prompt.Controls.Add(fileExtensionChecklist); prompt.AcceptButton = saveFilterButton; prompt.CancelButton = cancelButton; return(prompt.ShowDialog()); }