This may be a disadvantage of UserControl. You must republish the events and properties of one or more of the built-in controls. Consider an alternative: if this UserControl contains only a ListBox, you are much better off just inheriting the ListBox instead of the UserControl.
Anyhoo, you need to restart the SelectedIndexChanged event. And, of course, you will need to allow the client to read the currently selected item. In this way:
public partial class UserControl1 : UserControl {
public event EventHandler SelectedIndexChanged;
public UserControl1() {
InitializeComponent();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e) {
EventHandler handler = SelectedIndexChanged;
if (handler != null) handler(this, e);
}
public object SelectedItem {
get { return listBox1.SelectedItem; }
}
}
source
share