adrianjohnson
Programmer
Hello,
I've got a function which reads a text box, and creates a tabpage with a listbox on the fly. This means there may be more than one listbox at any one time.
Within my code, I create an event handler for the listbox. It fires off ok, but I'd like to get the selected text from the listbox, but I can't seem to retreive it. I know I can use the listbox.selecteditem etc code, but it doesn't work.
Here's my code:
The event handler code (I'm just trying to see what it returns) is:
Any ideas?
Thanks,
Adrian
I've got a function which reads a text box, and creates a tabpage with a listbox on the fly. This means there may be more than one listbox at any one time.
Within my code, I create an event handler for the listbox. It fires off ok, but I'd like to get the selected text from the listbox, but I can't seem to retreive it. I know I can use the listbox.selecteditem etc code, but it doesn't work.
Here's my code:
Code:
TabPage newPage = new TabPage(strLine);
// Create a list view, and add it to the new tab.
newList = new ListBox();
newPage.Controls.Add(newList);
newList.Dock = DockStyle.Fill;
newList.Click += new EventHandler(newList_Click);
The event handler code (I'm just trying to see what it returns) is:
Code:
private void newList_Click(object sender, EventArgs e)
{
MessageBox.Show(sender.GetType().ToString());
//MessageBox.Show(sender.ToString());
Console.WriteLine(sender.ToString());
}
Any ideas?
Thanks,
Adrian