CheckedListBox 和 EventArgs
我在这里做错了什么? 要温柔。
对于 CheckedListBox
,我可以简单地通过使用来更新项目:
private void button3_Click(object sender, EventArgs e)
{
checkedListBox4.Items.Add("whatever"); //or use an object
}
效果很好,但我想要做的是从另一个类中的方法向 CheckedListItem
发送一组项目
所以,我设置了另一个 class some:form1
,它有一个委托,该委托指向我调用的方法\invoke
委托以这种方式调用\调用:
public delegate void m_del(List<DirectoryInfo> ww, string rr);
代码中的其他位置:
m_del methtouse = new m_del(listme)
public void listme(List<DirectoryInfo> fi, string mypath)
{
foreach (DirectoryInfo j in fi)
{
mypath = null; //mypath used by another method
try
{
NewCheckboxListItem cb1 = new NewCheckboxListItem();
cb1.Tag = j.Name;
cb1.Text = j.Name;
checkedListBox4.Items.Add(cb1);
}
catch (Exception w)
{
MessageBox.Show(w.Message);
}
}
}
public class NewCheckboxListItem
{
// define a text and
// a tag value
public string Text;
public string Tag;
// override ToString(); this
// is what the checkbox control
// displays as text
public override string ToString()
{
return this.Text;
}
}
methtouse( a List<DirectoryInfo> ww, a string rr)
{}
发生的情况是 Item 集合checkedListBox4
已更新,并且具有与我发送的值一样多的值,但它不会绘制项目\显示
我尝试调用 checkedListBox4_datavaluememberchanged
方法和其他一些方法的 项目checkedListBox4_changed
事件,但集合中的项目再次更新,但它们没有出现在 CheckedListBox
中,
我认为这与没有 eventargs
有关code>
有没有一种简单的方法可以将成功的 CheckedListBox
的所有属性、事件和属性与不成功的 CheckedListBox
进行并排比较(以编程方式)
< strong>注意:该类继承自CheckedListBox
所在的form1
,并且方法访问权限设置为public。
What am I doing wrong here? be gentle.
For CheckedListBox
, I can update the items simply by using:
private void button3_Click(object sender, EventArgs e)
{
checkedListBox4.Items.Add("whatever"); //or use an object
}
works great, but what I want to do is send the CheckedListItem
a set of items from method within another class
So, I set up another class something:form1
that has a delegate that points to a method that I call\invoke
The delegate calls\invokes this way:
public delegate void m_del(List<DirectoryInfo> ww, string rr);
somewhere else in the code:
m_del methtouse = new m_del(listme)
public void listme(List<DirectoryInfo> fi, string mypath)
{
foreach (DirectoryInfo j in fi)
{
mypath = null; //mypath used by another method
try
{
NewCheckboxListItem cb1 = new NewCheckboxListItem();
cb1.Tag = j.Name;
cb1.Text = j.Name;
checkedListBox4.Items.Add(cb1);
}
catch (Exception w)
{
MessageBox.Show(w.Message);
}
}
}
public class NewCheckboxListItem
{
// define a text and
// a tag value
public string Text;
public string Tag;
// override ToString(); this
// is what the checkbox control
// displays as text
public override string ToString()
{
return this.Text;
}
}
methtouse( a List<DirectoryInfo> ww, a string rr)
{}
What happens is the Item collection in the checkedListBox4
is updated and has as many value as i send it, but it will not draw the item\show the item
I have tried calling a checkedListBox4_datavaluememberchanged
method and a few other checkedListBox4_changed
events but once again the items in the collection are updated but they do not appear in the CheckedListBox
I think its something to do with it not having eventargs
Is there an easy way to do a side by side comparison of ALL the attributes, events, properties of a successful CheckedListBox
with that of an unsuccessful CheckedListBox
(programmatically)
Note: The class inherits from form1
where the CheckedListBox
is located, and the methods access is set to public.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您缺少的是告诉 checkListBox 该对象的值应该是什么。
这告诉 CheckedListBox 使用与该确切字符串匹配的成员作为显示值。
https://stackoverflow.com/a/2023338/455536
http://msdn.microsoft.com/en-us/library/3yx132k0(v=vs.110) .aspx
What you are missing is to tell the checkedListBox what the value is supposed to be for that object.
That tells the CheckedListBox to use the member matching that exact string as the display value.
https://stackoverflow.com/a/2023338/455536
http://msdn.microsoft.com/en-us/library/3yx132k0(v=vs.110).aspx