I have this userControl
which contains ListBox
. I want to access that ListBox
from another userControl
.
For example:
UserControl1.ListBox1.Items.Count;
I have this userControl
which contains ListBox
. I want to access that ListBox
from another userControl
.
For example:
UserControl1.ListBox1.Items.Count;
Add A Public Property ItemsCount in your user control
public int ItemsCount
{
get { return ListBox1.Items.Count; }
}
or
public ListBox MyListBox
{
get { return ListBox1; }
}
to access the whole listbox
Make a property of ListBox
in your first usercontrol
and get that like
public ListBox lstBox
{
get { return this.listBox1;}
}
Now access the ListBox from other usercontrol like that
usercontrol1 obj = new usercontrol1();
int itemCount = obj.lstBox.Items.Count ;