主题:BeginInvoke 如何添加完整的 ListviewItem?
如何通过 BeginInvoke 添加列表视图子项 -> myDelegate 进程? 我尝试过各种版本的解决方案,但总是出错!
非常感谢您的帮助!
public delegate ListViewItem myDelegate(string aItem);
...
if (InvokeRequired)
{
ListViewItem lvwItem = new ListViewItem();
lvwItem.Text = strMessage;
lvwItem.SubItems.Add(".2.");
BeginInvoke(new myDelegate(listView1.Items.Add), new string[] { strMessage }); //works with a var of type string, but not for more Subitems.add()
}
我找到了答案,但我无法将其发布为答案,因为我必须等待 7 个小时....
我找到了解决方案,而不会导致我的多线程应用程序崩溃...我很愚蠢;)
在我的委托中我使用过字符串而不是 Listviewitem!
public delegate ListViewItem myDelegate2(ListViewItem aItem);
...
if (InvokeRequired)
{
//BeginInvoke(new myDelegate(listView1.Items.Add), new object[] { strMessage });
ListViewItem lvwItem = new ListViewItem();
lvwItem.Text = strMessage;
lvwItem.SubItems.Add(".2.");
BeginInvoke(new myDelegate2(listView1.Items.Add), new object[] { lvwItem });
}
how can i add listview subitems through the BeginInvoke -> myDelegate process ?
I've tried various versions of solutions, but allways with error!
thanks a lot for help!
public delegate ListViewItem myDelegate(string aItem);
...
if (InvokeRequired)
{
ListViewItem lvwItem = new ListViewItem();
lvwItem.Text = strMessage;
lvwItem.SubItems.Add(".2.");
BeginInvoke(new myDelegate(listView1.Items.Add), new string[] { strMessage }); //works with a var of type string, but not for more Subitems.add()
}
i found the answer, but i can't post it as answer because i have to wait up 7 hours....
i found the solution without crashing my multithreaded app... i'm stupid ;)
in my delegate i had used String instead of Listviewitem!
public delegate ListViewItem myDelegate2(ListViewItem aItem);
...
if (InvokeRequired)
{
//BeginInvoke(new myDelegate(listView1.Items.Add), new object[] { strMessage });
ListViewItem lvwItem = new ListViewItem();
lvwItem.Text = strMessage;
lvwItem.SubItems.Add(".2.");
BeginInvoke(new myDelegate2(listView1.Items.Add), new object[] { lvwItem });
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你似乎确实被束缚住了。试试这个:
You do seem to be getting rather tied up. Try this: