void Instance_DeviceAddedEvent(object sender, Utils.Devices.GarminMassStorage.DeviceInfoEventArgs e) { if (this.InvokeRequired) { this.Invoke(new EventHandler <Utils.Devices.GarminMassStorage.DeviceInfoEventArgs>(this.Instance_DeviceAddedEvent), new object[] { sender, e }); return; } comboBox1.Items.Add(e.Device); if (comboBox1.SelectedIndex < 0) { comboBox1.SelectedIndex = 0; } }
void Instance_DeviceRemovedEvent(object sender, Utils.Devices.GarminMassStorage.DeviceInfoEventArgs e) { if (this.InvokeRequired) { this.Invoke(new EventHandler <Utils.Devices.GarminMassStorage.DeviceInfoEventArgs>(this.Instance_DeviceRemovedEvent), new object[] { sender, e }); return; } Utils.Devices.GarminMassStorage.DeviceInfo dev = (from Utils.Devices.GarminMassStorage.DeviceInfo d in comboBox1.Items where d.DriveName == e.Device.DriveName select d).FirstOrDefault(); if (dev != null) { comboBox1.Items.Remove(dev); if (comboBox1.SelectedIndex < 0 && comboBox1.Items.Count > 0) { comboBox1.SelectedIndex = 0; } } }