C# listview之点击空白区仍然不失去选中项的状态

    要做出这个效果,不能在mouseclick,click事件响应函数中写代码,因为大部分空白区不会响应该事件,mousedown也不可,应用mouseup事件来响应该要求,代码如下:

 

private void listView1_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { WizardBase.IntermediateStep inter = (wizardControl1.WizardSteps[wizardControl1.CurrentStepIndex] as WizardBase.IntermediateStep); if (listView1.SelectedItems.Count > 0) { //if (ListViewTmpIndex != -1) //{ // listView1.Items[ListViewTmpIndex].Selected = false; //} //ListViewTmpIndex = listView1.Items[listView1.SelectedIndices[0]].Index; switch (listView1.Items[listView1.SelectedIndices[0]].Index) { case 0: //TODO:File if (inter != null) { inter.Subtitle = "打开一个或多个文件"; inter.Refresh(); } break; case 1: //TODO:Oracle if (inter != null) { inter.Subtitle = "连接一个OracleSpatial服务"; inter.Refresh(); } //wizardControl1. break; case 2: //TODO:PostgreSql if (inter != null) { inter.Subtitle = "连接一个PostGIS服务"; inter.Refresh(); } break; case 3: //TODO:ArcSDE if (inter != null) { inter.Subtitle = "连接一个Arc SDE服务"; inter.Refresh(); } break; case 4: //TODO:SQLServer if (inter != null) { inter.Subtitle = "连接一个SQLServer服务"; inter.Refresh(); } break; default: break; }//switch 选中的行 } else if (listView1.SelectedItems.Count <= 0)//点击空白区 { if (this.listView1.FocusedItem != null) { ListViewItem item = this.listView1.GetItemAt(e.X, e.Y); if (item == null) { this.listView1.FocusedItem.Selected = true; } } } }//left_button_up }//listView1_MouseUp 

你可能感兴趣的:(ListView,C#,null,PostgreSQL,sqlserver,button)