private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { ItemEvent.Invoke(this, new ItemEventArgs(listBox1.SelectedItem)); }
public class MyList { private string[] items; public event ItemEventHandler ItemEvent; public string this[int index] { get { return items[index]; } set { items[index] = value; if (ItemEvent != null) ItemEvent(this, new ItemEventArgs(index, value)); } } }In this example, a custom class called MyList is created that contains an event called ItemEvent and an indexer property that raises the event whenever an item is changed. The ItemEventArgs object contains the index and value of the changed item. Package/Library: None (this is a custom class)