当前位置:网站首页>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
边栏推荐
- SQLite 3.39.0 release supports right external connection and all external connection
- From 20s to 500ms, I used these three methods
- 451-memcpy、memmove、memset的实现
- MySQL表历史数据清理总结
- Conscience summary! Jupyter notebook from Xiaobai to master, the nanny tutorial is coming!
- 蓝牙芯片ble是什么,以及该如何选型,后续技术发展的路径是什么
- 简书自动阅读
- Function high order curry realization
- 良心总结!Jupyter Notebook 从小白到高手,保姆教程来了!
- Codeforces Round #802 (Div. 2) 纯补题
猜你喜欢

Embedded (PLD) series, epf10k50rc240-3n programmable logic device

How to avoid duplicate data in gaobingfa?

KT148A语音芯片ic的软件参考代码C语言,一线串口

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

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

Common problems and description of kt148a voice chip IC development

AcWing 1126. 最小花费 题解(最短路—dijkstra)

Kt148a voice chip IC software reference code c language, first-line serial port

自動生成VGG圖像注釋文件

Py之interpret:interpret的简介、安装、案例应用之详细攻略
随机推荐
股票证券公司排名,有安全保障吗
Kt148a voice chip IC software reference code c language, first-line serial port
《MongoDB入门教程》第03篇 MongoDB基本概念
使用 Cheat Engine 修改 Kingdom Rush 中的金钱、生命、星
自动生成VGG图像注释文件
How to set priorities in C language? Elaborate on C language priorities
452-strcpy、strcat、strcmp、strstr、strchr的实现
Implementation of 453 ATOI function
Golang:[]byte to string
Windows2008R2 安装 PHP7.4.30 必须 LocalSystem 启动应用程序池 不然500错误 FastCGI 进程意外退出
《代碼整潔之道》讀書筆記
AcWing 342. 道路与航线 题解 (最短路、拓扑排序)
Golang并发编程——goroutine、channel、sync
AcWing 1126. 最小花费 题解(最短路—dijkstra)
AcWing 1134. 最短路计数 题解(最短路)
多端小程序开发有什么好处?覆盖百度小程序抖音小程序微信小程序开发,抢占多平台流量红利
Data Lake (XII): integration of spark3.1.2 and iceberg0.12.1
AcWing 1128. Messenger solution (shortest path Floyd)
《重构:改善既有代码的设计》读书笔记(上)
Educational Codeforces Round 129 (Rated for Div. 2) 补题题解