当前位置:网站首页>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
边栏推荐
- 职场四象限法则:时间管理四象限与职场沟通四象限「建议收藏」
- Detailed tutorial on installing stand-alone redis
- Dictionaries
- AcWing 181. 回转游戏 题解(搜索—IDA*搜索)
- Windows2008R2 安装 PHP7.4.30 必须 LocalSystem 启动应用程序池 不然500错误 FastCGI 进程意外退出
- Reading notes of "the way to clean structure" (Part 2)
- MySQL function
- What is the Bluetooth chip ble, how to select it, and what is the path of subsequent technology development
- AcWing 383. 观光 题解(最短路)
- Horizontal ultra vires and vertical ultra vires [easy to understand]
猜你喜欢

字典

Yes, that's it!

rxjs Observable 自定义 Operator 的开发技巧

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

Refactoring: improving the design of existing code (Part 1)

Idea editor removes SQL statement background color SQL statement warning no data sources are configured to run this SQL And SQL dialect is not config

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

《MongoDB入门教程》第03篇 MongoDB基本概念

《重构:改善既有代码的设计》读书笔记(下)

After writing 100000 lines of code, I sent a long article roast rust
随机推荐
Registration opportunity of autowiredannotationbeanpostprocessor in XML development mode
多端小程序开发有什么好处?覆盖百度小程序抖音小程序微信小程序开发,抢占多平台流量红利
Shardingsphere jdbc5.1.2 about select last_ INSERT_ ID () I found that there was still a routing problem
Understanding and function of polymorphism
《代码整洁之道》读书笔记
Function high order curry realization
高并发下如何避免产生重复数据?
R language uses econcharts package to create microeconomic or macroeconomic maps, and indifference function to visualize indifference curve
安装单机redis详细教程
AcWing 383. Sightseeing problem solution (shortest circuit)
450-深信服面经1
Golang:[]byte to string
JS如何取整数
AcWing 1131. Saving Private Ryan (the shortest way)
Yes, that's it!
[error record] problems related to the installation of the shuttle environment (follow-up error handling after executing the shuttle doctor command)
PXE installation "recommended collection"
Build a master-slave mode cluster redis
Watchful pioneer world outlook Architecture - (how does a good game come from)
What is the Bluetooth chip ble, how to select it, and what is the path of subsequent technology development