private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) { int colIndex = e.ColumnIndex; DataGridViewColumn col = dataGridView1.Columns[colIndex]; foreach (DataChooser chooser in view.DataChoosers) { if (chooser.IsChooser() && col.Name.Equals(chooser.Column)) { string className = DBBrowserConstant.DATA_CHOOSER_PACKAGE + "." + chooser.Chooser + "ChooserForm"; Type chooserType = Type.GetType(className); if (chooserType == null) { MessageBox.Show("Chooser " + className + " is not implemented", "Chooser " + className + " is not implemented", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } object chooserObj = Activator.CreateInstance(chooserType); if (chooserObj is ChooserForm) { using (ChooserForm chooserForm = (ChooserForm)chooserObj) { chooserForm.ShowDialog(this); dataGridView1.Rows[e.RowIndex].Cells[colIndex].Value = chooserForm.SelectedValue; return; } } } } }
/// <summary> /// ''' Select ASCOM driver to use including pre-selecting one in the drop-down list /// ''' </summary> /// ''' <param name="DriverProgID">Driver to preselect in the chooser dialogue</param> /// ''' <returns>Driver ID of chosen driver</returns> /// ''' <exception cref="Exceptions.InvalidValueException">Thrown if the Chooser.DeviceType property has not been set before Choose is called. /// ''' It must be set in order for Chooser to know which list of devices to display.</exception> /// ''' <remarks>The supplied driver will be pre-selected in the Chooser's list when the chooser window is first opened. /// ''' </remarks> public new string Choose(string DriverProgID) { string selectedProgId; ChooserForm chooserFormInstance; try { if (string.IsNullOrEmpty(deviceTypeValue)) { throw new Exceptions.InvalidValueException("Unknown device type, DeviceType property has not been set"); } chooserFormInstance = new ChooserForm(); // Initially hidden chooserFormInstance.DeviceType = deviceTypeValue; chooserFormInstance.SelectedProgId = DriverProgID; chooserFormInstance.ShowDialog(); // Display MODAL Chooser dialogue selectedProgId = chooserFormInstance.SelectedProgId; chooserFormInstance.Dispose(); } catch (DriverNotRegisteredException ex) { MsgBox("Chooser Exception: " + ex.Message); LogEvent("Chooser", "Exception", EventLogEntryType.Error, EventLogErrors.ChooserException, ex.ToString); selectedProgId = ""; } catch (Exception ex) { Interaction.MsgBox("Chooser Exception: " + ex.ToString()); LogEvent("Chooser", "Exception", EventLogEntryType.Error, EventLogErrors.ChooserException, ex.ToString()); selectedProgId = ""; } return(selectedProgId); }