Well it depends what you want to achieve from the listbox's selected item.
There are a couple of possible ways, let me try to explain some of these for your homework.
Suppose you have a data table with two columns, and their rows...
ID Title
_________________________
1 First item's title
2 Second item's title
3 Third item's title
And you bind this data table to your list box as,
ListBox1.DisplayMember = "ID";
ListBox1.ValueMember = "Title";
If user selects second item from the list box.
Now if you want to get the display value (Title) of the selected item, then you can do
string displayValue = ListBox1.Text; // displayValue = Second item's title
OR even this to get same results.
// displayValue = Second item's title
string displayValue = ListBox1.SelectedItem.ToString();
And to get the value member against the selected item, you need to do
string selectedValue = ListBox1.SelectedValue; // selectedValue = 2
Now there are situations when you want to allow user to select more than one item from the list box, so you then set
ListBox1.SelectionMode = SelectionMode.MultiSimple;
OR
ListBox1.SelectionMode = SelectionMode.MultiExtended;
Now suppose if user selects two items; second and third.
So you can get the display values by simply iterating through the SelectedItems
string displayValues = string.Empty;
foreach (object selection in ListBox1.SelectedItems)
{
displayValues += selection.ToString() + ",";
}
// so displayValues = Second item's title, Third item's title,
And if you want to get ID's
instead of Title's
then...
I am also looking through it, I will post if found.
I hope your understandings build.
Good Luck!