首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CheckedListBox和EventArgs

CheckedListBox和EventArgs
EN

Stack Overflow用户
提问于 2009-07-26 16:45:08
回答 1查看 1.6K关注 0票数 0

我在这里做错什么了?请温柔些。

对于CheckedListBox,我可以简单地使用以下命令更新这些项:

代码语言:javascript
复制
private void button3_Click(object sender, EventArgs e)
{
    checkedListBox4.Items.Add("whatever"); //or use an object
}

工作很好,但我想做的是从另一个类中的方法向CheckedListItem发送一组项。

因此,我设置了另一个class something:form1,它有一个委托,指向我调用的方法

委托调用\以这种方式调用:

代码语言:javascript
复制
public delegate void m_del(List<DirectoryInfo> ww, string rr);

代码中的其他地方:

代码语言:javascript
复制
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。

EN

回答 1

Stack Overflow用户

发布于 2014-02-22 13:37:07

您所缺少的是告诉checkedListBox该对象的值应该是什么。

代码语言:javascript
复制
checkedListBox4.ValueMember = "Text";

这告诉CheckedListBox使用匹配该精确字符串的成员作为显示值。

https://stackoverflow.com/a/2023338/455536

http://msdn.microsoft.com/en-us/library/3yx132k0(v=vs.110).aspx

指定从数据源中提取值.

的属性的字符串

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1184986

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档