|
Here is my code:
private void loadDataToolStripMenuItem_Click(object sender, EventArgs e)
{
TabPage tp = new TabPage();
tp.Text = "Data";
System.Windows.Forms.CheckedListBox AvailableDataList = new system.Windows.Forms.CheckedListBox();
AvailableDataList.Dock=DockStyle.Fill;
tp.Controls.Add(AvailableDataList);
for (bb = 0; bb < 8; bb++)
{
AvailableDataList.Items.Add("Bob");
switch(SelectName(bb))
{
case false:
AvailableDataList.SetItemChecked(bb, false);
break;
case true:
AvailableDataList.SetItemChecked(bb, true);
}
tabControl1.TabPages.Add(tp);
}
private void button4_Click(object sender, EventArgs e)
{
label1.text = AvailableDataList.Items.Count;
}
The code under the loadDataToolStripMenuItem works just fine.
I’m creating a CheckedListBox, populating it, then creating (adding) a TabPage, and placing the CheckedListBox on the new tab.
Problem is the created CheckedListBox AvailableDataList is not accessible in the button4_Click routine.
I don’t know how to make it public throughout the form.
Can someone help?
Thanks!
|
|
|
|
|
At the moment it is a method level variable, you need to make it a class level one:
System.Windows.Forms.CheckedListBox AvailableDataList;
private void loadDataToolStripMenuItem_Click(object sender, EventArgs e)
{
TabPage tp = new TabPage();
tp.Text = "Data";
AvailableDataList = new system.Windows.Forms.CheckedListBox();
AvailableDataList.Dock=DockStyle.Fill;
tp.Controls.Add(AvailableDataList);
for (bb = 0; bb < 8; bb++)
{
AvailableDataList.Items.Add("Bob");
switch(SelectName(bb))
{
case false:
AvailableDataList.SetItemChecked(bb, false);
break;
case true:
AvailableDataList.SetItemChecked(bb, true);
}
tabControl1.TabPages.Add(tp);
}
private void button4_Click(object sender, EventArgs e)
{
if(AvailableDataList != null)
label1.text = AvailableDataList.Items.Count;
}
|
|
|
|