/// <summary> /// Edits the specified object's value using the editor style indicated by the /// <see cref="M:System.Drawing.Design.UITypeEditor.GetEditStyle"/> method. /// </summary> /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"/> that can be /// used to gain additional context information.</param> /// <param name="provider">An <see cref="T:System.IServiceProvider"/> that this editor can use to /// obtain services.</param> /// <param name="value">The object to edit.</param> /// <returns> /// The new value of the object. If the value of the object has not changed, this should return the /// same object it was passed. /// </returns> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { var svc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService; if (svc != null) { using (var editorForm = new AllianceUITypeEditorForm(value)) { var pt = context.PropertyDescriptor.PropertyType; if (svc.ShowDialog(editorForm) == DialogResult.OK) { if (pt == typeof(QuestRequirementCollection<User>)) value = editorForm.SelectedItem.ID; else { const string errmsg = "Don't know how to handle the source property type `{0}`. In value: {1}. Editor type: {2}"; if (log.IsErrorEnabled) log.ErrorFormat(errmsg, pt, value, editorForm.GetType()); Debug.Fail(string.Format(errmsg, pt, value, editorForm.GetType())); } } } } return value; }
/// <summary> /// Handles the Click event of the btnAlliance control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> void btnAlliance_Click(object sender, EventArgs e) { using (var f = new AllianceUITypeEditorForm(pgAlliance.SelectedObject)) { if (f.ShowDialog(this) != DialogResult.OK) { return; } var item = f.SelectedItem; pgAlliance.SelectedObject = new EditorAlliance(item.ID, _dbController); } }
/// <summary> /// Handles the Click event of the btnBrowse control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> void btnBrowse_Click(object sender, EventArgs e) { using (var f = new AllianceUITypeEditorForm(null)) { // If we require distinct, skip items we already have in the list if (RequireDistinct) { var listItems = lstItems.Items.OfType<AllianceID>().ToImmutable(); f.SkipItems = (x => listItems.Any(y => y == x.ID)); } if (f.ShowDialog(this) != DialogResult.OK) return; var item = f.SelectedItem; _selectedItem = item.ID; txtItem.Text = item.ID + " [" + item.Name + "]"; } }