Update value with Enter

Mar 4, 2011 at 12:09 PM


great project! Only one small thing I've missed: settings values with the enter button.
It's pretty simple to implement in case someone needs it.

Add the PrviewKeyDown Event in the constructor of PropertyGrid.cs:

 public PropertyGrid()
            PreviewMouseDown += new MouseButtonEventHandler(PropertyGrid_PreviewMouseDown);
            PreviewKeyDown += new KeyEventHandler(PropertyGrid_PreviewKeyDown);


and add the eventhandler: 

void PropertyGrid_PreviewKeyDown(object sender, KeyEventArgs e)
            if (e.Key == Key.Enter && e.OriginalSource is TextBox)
                this.SelectedProperty.Value = ((TextBox)e.OriginalSource).Text;
Wasn't tested thoroughly but it seems to work! Cheers

Mar 4, 2011 at 2:32 PM

I've included this patch to the source. I also did another change, so that with the Down Button the Entry is also finished, and it is moved to the next Property!

Mar 4, 2011 at 3:08 PM

Nice :) Maybe add 


if (this.SelectedProperty != null)
this.SelectedProperty.Value = ....
too, don't want to be responsible for any crashes!

Mar 4, 2011 at 4:11 PM

You're right, that would be better! I added it!