I am having an issue with the propertyGrid.
I have a class called DummySettings that is mapped to the propertyGrid
I have a property “Name”
When typing something in the propertygrid EG the Name property I would like to raise an event that “TextChanged”
Despite implementing the INotifyPropertyChanged event and raising it and despite hooking all sorts of events I can think of on the propertyGrid
none of this events fires when A text changes.
Am I missing the obvious?
EDITED
Psuedo Code
public class DummySettings : INotifyPropertyChanged
{
private string name;
[DisplayName("Name")]
public string Name
{
get { return name; }
set
{
if (name != value)
{
name = value;
OnPropertyChanged("Name");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}
//UserControl
public partial class DummyControl : UserControl
{
private DummySettings settings;
///Constructor
public DummyControl()
{
InitializeComponent();
settings = new DummySettings();
propertyGrid1.SelectedObject = settings;
settings.PropertyChanged += OnDummyPropertyChanged;
//All the events I have hooked up but not firing when text is changed
private void OnDummyPropertyChanged(object sender, PropertyChangedEventArgs e)
{
btnToEnable.Enabled = HasName();
}
private void propertyGrid1_Leave(object sender, EventArgs e)
{
btnToEnable.Enabled = HasName();
}
private void propertyGrid1_Validating(object sender, CancelEventArgs e)
{
btnToEnable.Enabled = HasName();
}
private void propertyGrid1_SelectedObjectsChanged(object sender, EventArgs e)
{
btnToEnable.Enabled = HasName();
}
private void propertyGrid1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
btnToEnable.Enabled = HasName();
}
private bool HasName()
{
return settings.Name.IsNotNullOrEmpty();
}
You can use PropertyValueChanged event to get notified of selected object property changed in PropertyGrid. So, when you are changed
Nameproperty value from “Foo” to “Bar”, this event will be raised: