Completed
Last Updated: 31 Mar 2014 10:21 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 17 Oct 2013 02:43
Category: PropertyGrid
Type: Bug Report
1
FIX. RadPropertyGrid - PropertyValueChanging event fires twice when MessageBox is shown in the event handler code
To reproduce: -add a RadPropertyGrid and use the following code: radPropertyGrid.SelectedObject = new MyPropertyGridAdapter(node); PropertyValueChanging += new PropertyGridItemValueChangingEventHandler(OnPropertyValueChanging); private void OnPropertyValueChanging(object sender, PropertyGridItemValueChangingEventArgs e) { var form = new CommentActionForm(); if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK) { var item = e.Item as PropertyGridItem; var pd = item.PropertyDescriptor as MyPropertyDescriptor; if (pd != null) { // Perform value change (affects database). } } else { e.Cancel = true; } } Workaround:when ending edit mode with Enter key you may use the following approach: public Form1() { InitializeComponent(); this.radPropertyGrid1.SelectedObject = new MyObject(10204, "Sample name", "Some descripion"); this.radPropertyGrid1.EditorRequired += radPropertyGrid1_EditorRequired; } private void radPropertyGrid1_EditorRequired(object sender, PropertyGridEditorRequiredEventArgs e) { PropertyGridItem propertyItem = e.Item as PropertyGridItem; e.Editor = new MyEditor(propertyItem); } public class MyObject { public int ID { get; set; } public string Name { get; set; } public string Description { get; set; } public MyObject(int iD, string name, string description) { this.ID = iD; this.Name = name; this.Description = description; } } public class MyEditor : PropertyGridTextBoxEditor { public string InitialValue { get; set; } public PropertyGridItem PropertyItem { get; set; } public MyEditor(PropertyGridItem item) : base() { this.PropertyItem = item; } public override void BeginEdit() { InitialValue = this.TextBoxEditorElement.Text; base.BeginEdit(); } } public class MyPropertyGrid : RadPropertyGrid { protected override bool ProcessDialogKey(Keys keyData) { if (this.ActiveEditor != null && this.ActiveEditor is MyEditor && keyData == Keys.Enter) { MyEditor editor = ((MyEditor)this.ActiveEditor); PropertyGridItem property = editor.PropertyItem; string initialValue = editor.InitialValue; DialogResult ds = RadMessageBox.Show("Are you sure?", "Title", MessageBoxButtons.OKCancel, RadMessageIcon.Question); if (ds == System.Windows.Forms.DialogResult.Cancel) { property.Value = initialValue; return false; } } return base.ProcessDialogKey(keyData); } }
0 comments