如何从User Control向CheckedListBox添加项目 [英] How to add item to CheckedListBox from User Control
本文介绍了如何从User Control向CheckedListBox添加项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
EveryOne!
我有一个包含两个控件的用户控件:
1.按钮
2. CheckedListBox
目前我想将物品从主表格添加到checkdedlistbox。
这可能吗?
任何意见或建议非常感谢!
谢谢!
环境:Visual studio express 2013 for desktop
语言:C# 。
平台:Winform
Hi, EveryOne!
I have a user control that contains two controls:
1. Button
2. CheckedListBox
Currently I want to add the item to checkdedlistbox from main form.
this is possible?
Any comments or suggestions are very grateful!
Thank you!
Environment: Visual studio express 2013 for desktop
Language: C#.
Platforms: Winform
推荐答案
你可以给usercontol你需要的功能/属性
you can give the usercontol the functions/properties you need
public partial class MyUserControl : UserControl
{
public MyUserControl()
{
InitializeComponent();
}
public int CheckedListBoxAddItems(object item)
{
return checkedListBox1.Items.Add(item);
}
}
}
然后从您的表单代码中调用它们
and then call them from your form code
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
myUserControl1.CheckedListBoxAddItems("item1");
myUserControl1.CheckedListBoxAddItems("item2");
myUserControl1.CheckedListBoxAddItems("item3");
}
这篇关于如何从User Control向CheckedListBox添加项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文