// called when a device is unplugged public void deviceRemoval(YModule m) { //Cycle on All DropDown gauges for (int j = 0; j < gauges.GetLength(0); j++) { ComboBox d = gauges[j].getDropDown(); int selected = d.SelectedIndex; // cycle on all gauge dropdown items for (int i = d.Items.Count - 1; i >= 0; i--) { //search for function stored in the drop down list MyTemperature mt = (MyTemperature)d.Items[i]; YTemperature t = mt.getYTemperature(); // test if the fucntion parent module is the the one removed // note : it's too late to use get_module on t, so with use // a little trick: with stored the module serial in the function // userdate. if ((string)t.get_userData() == m.get_serialNumber()) { // remove it from the drop down d.Items.RemoveAt(i); // selected index update if (selected == i) { selected--; } if (selected >= d.Items.Count) { selected = d.Items.Count - 1; } } } if (selected >= 0) { d.SelectedIndex = selected; } } // disable empty dropdowns for (int j = 0; j < gauges.GetLength(0); j++) { ComboBox d = gauges[j].getDropDown(); if (d.Enabled && d.Items.Count <= 0) { d.Enabled = false; } } }
// poll temperature function for all gauges and // update UI acordingly private void refreshUI() { for (int j = 0; j < gauges.GetLength(0); j++) { ComboBox d = gauges[j].getDropDown(); if (d.Enabled) { if (d.SelectedIndex >= 0) { MyTemperature mt = (MyTemperature)d.Items[d.SelectedIndex]; YTemperature t = mt.getYTemperature(); gauges[j].setValue(t.get_currentValue()); } } gauges[j].refresh(); } }