private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) { int selectedCount = listView1.SelectedIndices.Count; if (selectedCount > 0) { int index = listView1.SelectedIndices[0]; List <NetDeviceInfo> netDeviceList = myfoundNetDeviceList.GetNetDeviceList(); NetDeviceInfo selectedDevice = netDeviceList[index]; SelectedNetDeviceIp = selectedDevice.Ip; SN = selectedDevice.SN; } }
private void UpdateNetDeviceListUI() { this.listView1.BeginUpdate(); //数据更新,UI暂时挂起,直到EndUpdate绘制控件,可以有效避免闪烁并大大提高加载速度 List <NetDeviceInfo> netDeviceList = myfoundNetDeviceList.GetNetDeviceList(); NetDeviceInfo device = null; int count = netDeviceList.Count; this.listView1.Items.Clear(); for (int i = 0; i < count; i++) //添加10行数据 { device = netDeviceList[i]; ListViewItem lv = new ListViewItem(); lv.Text = i.ToString(); lv.SubItems.Add(device.SN); lv.SubItems.Add(device.Ip); lv.SubItems.Add(device.Version); this.listView1.Items.Add(lv); } this.listView1.EndUpdate(); //结束数据处理,UI界面一次性绘制。 }