我在这里做错什么了?请温柔些。
对于CheckedListBox,我可以简单地使用以下命令更新这些项:
private void button3_Click(object sender, EventArgs e)
{
checkedListBox4.Items.Add("whatever"); //or use an object
}工作很好,但我想做的是从另一个类中的方法向CheckedListItem发送一组项。
因此,我设置了另一个class something:form1,它有一个委托,指向我调用的方法
委托调用\以这种方式调用:
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)
{} 发生的情况是,checkedListBox4中的项集合被更新,具有与我发送的一样多的值,但是它不会绘制项目\显示该项
我尝试过调用checkedListBox4_datavaluememberchanged方法和其他几个checkedListBox4_changed事件,但是集合中的项再次被更新,但它们没有出现在CheckedListBox中。
我想这和没有eventargs有关
是否有一种简单的方法可以对成功的CheckedListBox的所有属性、事件、属性和不成功的CheckedListBox (以编程方式)进行并行比较?
注意:类继承自CheckedListBox所在的form1,方法访问设置为public。
发布于 2014-02-22 13:37:07
您所缺少的是告诉checkedListBox该对象的值应该是什么。
checkedListBox4.ValueMember = "Text";这告诉CheckedListBox使用匹配该精确字符串的成员作为显示值。
https://stackoverflow.com/a/2023338/455536
http://msdn.microsoft.com/en-us/library/3yx132k0(v=vs.110).aspx
指定从数据源中提取值.
的属性的字符串
https://stackoverflow.com/questions/1184986
复制相似问题