当前位置:网站首页>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
边栏推荐
- JS如何取整数
- End to end object detection with transformers (Detr) paper reading and understanding
- 解决方案:VS2017 无法打开源文件 stdio.h main.h 等头文件[通俗易懂]
- rxjs Observable 自定义 Operator 的开发技巧
- 职场四象限法则:时间管理四象限与职场沟通四象限「建议收藏」
- AcWing 343. 排序 题解(floyd性质实现传递闭包)
- RPD出品:Superpower Squad 保姆级攻略
- Mobile robot path planning: artificial potential field method [easy to understand]
- 蓝牙芯片ble是什么,以及该如何选型,后续技术发展的路径是什么
- ShardingSphere-JDBC5.1.2版本关于SELECT LAST_INSERT_ID()本人发现还是存在路由问题
猜你喜欢

Reading notes of "the way to clean structure" (Part 2)

Istio1.12:安装和快速入门

End to end object detection with transformers (Detr) paper reading and understanding

KS004 基于SSH通讯录系统设计与实现

Educational Codeforces Round 129 (Rated for Div. 2) 补题题解

编写完10万行代码,我发了篇长文吐槽Rust

Data Lake (XII): integration of spark3.1.2 and iceberg0.12.1

Kt148a voice chip IC user end self replacement voice method, upper computer

Educational codeforces round 129 (rated for Div. 2) supplementary problem solution

Dictionaries
随机推荐
4274. Suffix expression - binary expression tree
多端小程序开发有什么好处?覆盖百度小程序抖音小程序微信小程序开发,抢占多平台流量红利
Build a master-slave mode cluster redis
Usage of ieda refactor
SQLite 3.39.0 release supports right external connection and all external connection
AcWing 1128. 信使 题解(最短路—Floyd)
AcWing 1135. 新年好 题解(最短路+搜索)
AcWing 1126. Minimum cost solution (shortest path Dijkstra)
Embedded (PLD) series, epf10k50rc240-3n programmable logic device
SIFT feature point extraction "suggestions collection"
Correspondence between pytoch version, CUDA version and graphics card driver version
KT148A语音芯片ic的硬件设计注意事项
Mobile robot path planning: artificial potential field method [easy to understand]
450 Shenxin Mianjing 1
Golang:[]byte to string
KT148A语音芯片ic的用户端自己更换语音的方法,上位机
Chapter 7 - class foundation
Getting started with typescript
《架构整洁之道》读书笔记(下)
KS004 基于SSH通讯录系统设计与实现