I have a function that deselect all selected items in the listbox when the user right clicks on listbox. Is there a way to apply this function to all listboxes in my project?
I want to know if there’s another way , not making a class and put the function in the class etc:
public class selectedListbox{
private void setSelected(ListBox details){
details.MouseDown += new System.Windows.Forms.MouseEventHandler(this.listBoxDeselectAll);
}
private void listBoxDeselectAll(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
((ListBox)sender).ClearSelected();
}
}
}
and then for each listbox to do this:
selectedListBox h = new selectedListBox();
h.setSelected(listboxNameHere);
maybe with an extension + lambda?
this way you can do the following without having to instantiate a new class or having to have all your listboxes be a derived class:
etc.