CheckedListBox 和 EventArgs

发布于 2024-07-29 07:24:50 字数 1959 浏览 5 评论 0原文

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

对于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空名 2024-08-05 07:24:50

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

checkedListBox4.ValueMember = "Text";

这告诉 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.

checkedListBox4.ValueMember = "Text";

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

A string that specifies the property of the data source from which to draw the value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文