private void UpdateList() { List <USBDrive> tmp = new List <USBDrive>(); ManagementObjectSearcher theSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive WHERE InterfaceType='USB'"); foreach (ManagementObject currentObject in theSearcher.Get()) { USBDrive tmpu = new USBDrive(currentObject); tmp.Add(tmpu); } if (tmp.Count != usbdrives.Count) { debugMessages.Text += "\r\nDevice list changed! Refreshing."; usbdrives.Clear(); driveList.Items.Clear(); int c = 0; foreach (USBDrive drive in tmp) { usbdrives.Add(drive); driveList.Items.Add(drive.Model + " (" + drive.Size + " GB)"); if (c == 0) { usbModel.Text = drive.Model; usbSerial.Text = drive.SerialNumber; selectedSerial = drive.SerialNumber; } c++; } } }
private void driveList_SelectedValueChanged(object sender, EventArgs e) { int idx = driveList.SelectedIndex; USBDrive tmp = usbdrives[idx]; usbModel.Text = tmp.Model; usbSerial.Text = tmp.SerialNumber; selectedSerial = tmp.SerialNumber; }