|
一个窗体里面有两个listView,分别是:listView1和listView2。我让两可操作可以同步,现在可以选择同步了,但闪的厉害。看代码:
private void listView1_Click(object sender, EventArgs e)//当单击listView1时
{
listView2.Focus();
if (listView1.SelectedItems.Count > 0)
{
int Num = Convert.ToInt32(listView1.SelectedItems[0].Index.ToString());//获取当前行号
listView2.Items[Num].Selected = true;
}
}
private void listView2_Click(object sender, EventArgs e)//当单击listViiew2时
{
listView1.Focus();
if (listView1.SelectedItems.Count > 0)
{
int Num = Convert.ToInt32(listView2.SelectedItems[0].Index.ToString());//获取当前行号
listView1.Items[Num].Selected = true;
}
}
我测试了,感觉是Focus()原因,但不用他得话就不会获得焦点。就不能同步选择上。
补充内容 (2014-11-6 13:10):
private void listView2_Leave(object sender, EventArgs e)
{
if (listView2.SelectedItems.Count > 0)
{
listView2.SelectedItems[kk].BackColor = SystemCo...
补充内容 (2014-11-6 13:11):
private void listView2_Leave(object sender, EventArgs e)
这个事件引起闪屏,还有没有更好的方法能达到同样的效果呀??? |
|