//lvAccount为listview控件
WebLogin(lvAccount.Items[i].Text, lvAccount.Items[i].SubItems[1].Text);
上面这句会提示这个错误【线程间操作无效: 从不是创建控件“listview”的线程访问它】
后来我查了网上信息改为下面这个,但是获取不到值,高手来帮帮我吧
delegate ListViewItem GetMessage(int rows);
//获取ListView值
private ListViewItem GetListViewValue(int rows)
{
ListViewItem lvi = new ListViewItem();
if (this.lvAccount.InvokeRequired)
{
GetMessage gm = new GetMessage(GetListViewValue);
this.lvAccount.Invoke(gm, rows);
}
else
{
lvi.SubItems[0].Text = lvAccount.Items[rows].Text;
lvi.SubItems.Add(lvAccount.Items[rows].SubItems[1].Text);
}
return lvi;
}
哪里错了,希望帮帮忙
调试了下,发现ELSE不会执行,是什么原因?
fgffggdf
....................
string strTempName = "", strTempPwd = "";
delegate void GetMessage(int rows);
//获取ListView值
private void GetListViewValue(int rows)
{
ListViewItem lvi = new ListViewItem();
if (this.lvAccount.InvokeRequired)
{
GetMessage gm = new GetMessage(GetListViewValue);
this.lvAccount.Invoke(gm, rows);
}
else
{
strTempName = lvAccount.Items[rows].Text;
strTempPwd = lvAccount.Items[rows].SubItems[1].Text;
}
}
不能设有返回值,好像线程不能有返回值,改为这个可以了