You can create event in StringClass:
public class StringClass
{
//...
public delegated void SelectedIndexChangedHandler(object sender, int index);
public event SelectedIndexChangedHandler SelectedIndexChanged;
public void OnSelectedIndexChanged(int index)
{
if (SelectedIndexChanged != null)
SelectedIndexChanged(this, index);
}
//.....
}
and fire this event from StringClassEditor:
private void ListBox_SelectedIndexChanged(object sender, EventArgs e)
{
ListBox lb = (ListBox) sender;
editedSc.StrValue = (string)lb.SelectedItem;
editSc.OnSelectedIndexChanged(lb.SelectedIndex);
}
But more simply will be following:
public class StringClass
{
//......
private string strValue;
public string Value
{
get {return strValue;}
set
{
if (strValue != value)
{
strValue = value;
OnChanged();
}
}
}
public EventHandler Changed;
public void OnChanged()//notify about changes
{
if (Changed != null)
Changed(this, EventArgs.Empty);
}
}
and in StringClassEditor:
private void ListBox_SelectedIndexChanged(object sender, EventArgs e)
{
ListBox lb = (ListBox) sender;
editedSc.Value = (string)lb.SelectedItem; //after value changing StringClass.Change event will fire.
}
private void ListBox_KeyDown(object sender, KeyEventArgs e)
{
if (wse != null && (e.KeyCode == Keys.Escape || e.KeyCode == Keys.Return))
{
if (e.KeyCode == Keys.Escape)
editedSc.Value = originalValue;
//return to original value
wse.CloseDropDown();
}
}
in this case you can connect to StringClass.Changed event to be notified about changes.