当前位置:网站首页>CheckListBox control usage summary
CheckListBox control usage summary
2022-07-02 19:42:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun . It is generally believed :foreach (object obj in checkedListBox1.SelectedItems) You can traverse the selected value . In fact, the traversal here is only the highlighted value, not the checked value . To traverse the checked value, use the following code :
for ( int i = 0; i < checkedListBox1.Items.Count; i++) { if (checkedListBox1.GetItemChecked(i)) { MessageBox.Show(checkedListBox1.GetItemText(checkedListBox1.Items[i])); } }
//
textBox1.Clear(); for (int i = 0; i < checkedListBox1.Items.Count; i++) { if (checkedListBox1.GetItemChecked(i)) { textBox1.Text+= checkedListBox1.GetItemText(checkedListBox1.Items[i]); } }
//
Reference resources :
Recently used checklistbox Control , In the process of using it , Spent more time , Here I collected the relevant code snippets , I hope that's helpful . 1. Add item checkedListBox1.Items.Add( “ Blue “); checkedListBox1.Items.Add( “ Red “); checkedListBox1.Items.Add( “ yellow “); 2. Judgment No. i Whether the item is selected , Selected as true, Otherwise false if(checkedListBox1.GetItemChecked(i)) { return true; } else { return false; } 3. Set the first i Whether the item is selected checkedListBox1.SetItemChecked(i, true); // true Change it to false Is not selected . 4. Set select all Add a name select_all Of checkbox Control , Controlled by it checkedListBox Whether to choose all or not . private void select_all_CheckedChanged( object sender, EventArgs e) { if(select_all.Checked) { for ( int j = 0; j < checkedListBox1.Items.Count; j++) checkedListBox1.SetItemChecked(j, true); } else { for ( int j = 0; j < checkedListBox1.Items.Count; j++) checkedListBox1.SetItemChecked(j, false); } } 5. Get all the selected values , And combine the text of the selected item into a string . string strCollected = string.Empty; for ( int i = 0; i < checkedListBox1.Items.Count; i++) { if (checkedListBox1.GetItemChecked(i)) { if (strCollected == string.Empty) { strCollected = checkedListBox1.GetItemText( checkedListBox1.Items[i]); } else { strCollected = strCollected + “ / “ + checkedListBox1. GetItemText(checkedListBox1.Items[i]); } } } 6. Set up CheckedListBox pass the civil examinations i Term Checked state checkedListBox1.SetItemCheckState(i, CheckState.Checked); 7. private void checkBoxAll_CheckedChanged( object sender, EventArgs e) { if (checkBoxAll.Checked) { // If you are selected, you will CheckedListBox All entries in become Checked state for ( int i = 0; i < checkedListBoxLayerControl.Items.Count; i++) { checkedListBoxLayerControl.SetItemCheckState(i, CheckState.Checked); } } else { // Otherwise it will become Unchecked state for ( int i = 0; i < checkedListBoxLayerControl.Items.Count; i++) { checkedListBoxLayerControl.SetItemCheckState(i, CheckState.Unchecked); } } } 8. checkedListBox Radio settings ( Code implementation ) private void chkl_ItemAuditing_ItemCheck( object sender, ItemCheckEventArgs e) { if (chkl_ItemAuditing.CheckedItems.Count > 0) { for ( int i = 0; i < chkl_ItemAuditing.Items.Count; i++) { if (i != e.Index) { this.chkl_ItemAuditing.SetItemCheckState(i, System.Windows.Forms.CheckState.Unchecked); } } } } 9. checkedListBox1 Display all records corresponding to keywords in a database for ( int i = 0; i < table.Rows.Count; i++) { string name = table.Rows[ “ myname “].ToString(); string paw = table.Rows[ “ mypaw “].ToString(); checkedListBox1.Items.Add(name + paw); } 10. for(i= 0;i<CheckedListBox.Items.Count;i++) { if(CheckedListBox.GetItemText( CheckedListBox.Items)== “ The value you get “) { CheckedListBox.SetItemChecked(i, true); } } 11. eliminate checkedListBox1 All options in for ( int i = 0; i < checkedListBox1.Items.Count; i++) { checkedListBox1.Items.Clear(); } 12. // Set the index to index The item of is selected for ( int i = 0; i < checkedListBox1.Items.Count; i++) { checkedListBox1.SetItemChecked(i, true); } 13. for ( int i = 0; i < checkedListBox1.Items.Count; i++) { if (checkedListBox1.GetSelected(i)) { MessageBox.Show(checkedListBox1.CheckedItems.ToString()); } } 14. // Choose checkedListBox1 All the options for ( int i = 0; i < checkedListBox1.Items.Count; i++) { checkedListBox1.SetItemCheckState(i, CheckState.Checked); } 15. for ( int i = 0; i < checkedListBox1.Items.Count; i++) { // If checkedListBox1 Of the i Item selected , // Is displayed checkedListBox1 Corresponding value if (checkedListBox1.GetItemChecked(i)) { MessageBox.Show(checkedListBox1.Items.ToString()); } } 16. // Reverse selection checkedListBox1 The option to for ( int i = 0; i < checkedListBox1.Items.Count; i++) { if (checkedListBox1.GetItemChecked(i)) { checkedListBox1.SetItemChecked(i, false); } else { checkedListBox1.SetItemChecked(i, true); } } 17. // checkedListBox1 Selected item in ->checkedListBox2 for ( int i = 0; i < checkedListBox1.CheckedItems.Count; i++) { checkedListBox2.Items.Add( this.checkedListBox1.CheckedItems); // remove Is to remove a specific value , No index, Pay attention this.checkedListBox1.Items.Remove( this.checkedListBox1.CheckedItems); }
18.
// Data binding
checkedListBox1.DataSource = dt;
checkedListBox1.DisplayMember = “item”;
checkedListBox1.ValueMember = “code”;
This attribute is in checklistbox It's not in there , But it can be used directly
19.
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
if (checkedListBox1.GetItemChecked(i))
{
checkedListBox1.SelectedIndex = i;
// utilize SelectedValue obtain Value When the value of , Only the value of the current focus item can be obtained . So we should treat the whole CheckedListBox All checkmarks in , Let them do the focus item once to get the value of all checked items .
str+= checkedListBox1.SelectedValue;
}
}
20.
CheckedlistBox Control is more useful. The two properties are CheckOnClick by True: It means to select the current row by clicking , by False : Point twice before you can select .( The default value is False). There is also an attribute of ThreeDCheckBoxes by True: A checkmark representing three dimensions , by False: Display marks indicating the surface .( The default value is False).
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/148570.html Link to the original text :https://javaforall.cn
边栏推荐
- Data Lake (XII): integration of spark3.1.2 and iceberg0.12.1
- 《重构:改善既有代码的设计》读书笔记(下)
- 安装单机redis详细教程
- AcWing 903. Expensive bride price solution (the shortest path - building map, Dijkstra)
- 基于SSM实现网上购物商城系统
- AcWing 342. Road and route problem solving (shortest path, topological sorting)
- Notes de lecture sur le code propre
- Yes, that's it!
- Registration opportunity of autowiredannotationbeanpostprocessor under annotation development mode
- MySQL表历史数据清理总结
猜你喜欢
AcWing 1126. 最小花费 题解(最短路—dijkstra)
Introduction to mongodb chapter 03 basic concepts of mongodb
Reading notes of "the way to clean structure" (Part 2)
What is the Bluetooth chip ble, how to select it, and what is the path of subsequent technology development
蓝牙芯片ble是什么,以及该如何选型,后续技术发展的路径是什么
Py's interpret: a detailed introduction to interpret, installation, and case application
Kt148a voice chip instructions, hardware, protocols, common problems, and reference codes
Refactoring: improving the design of existing code (Part 2)
Automatically generate VGg image annotation file
Istio1.12:安装和快速入门
随机推荐
Automatically generate VGg image annotation file
冒泡排序数组
Zabbix5 client installation and configuration
Cuckoo filter
AcWing 343. 排序 题解(floyd性质实现传递闭包)
From 20s to 500ms, I used these three methods
安装单机redis详细教程
SIFT feature point extraction "suggestions collection"
AcWing 341. 最优贸易 题解 (最短路、dp)
Which video recording software is better for the computer
What is the Bluetooth chip ble, how to select it, and what is the path of subsequent technology development
AcWing 903. Expensive bride price solution (the shortest path - building map, Dijkstra)
AcWing 1135. 新年好 题解(最短路+搜索)
MySQL
Kt148a voice chip IC software reference code c language, first-line serial port
Shardingsphere jdbc5.1.2 about select last_ INSERT_ ID () I found that there was still a routing problem
AcWing 383. Sightseeing problem solution (shortest circuit)
End to end object detection with transformers (Detr) paper reading and understanding
Correspondence between pytoch version, CUDA version and graphics card driver version
AcWing 1126. Minimum cost solution (shortest path Dijkstra)