Hi kznaneswar, Have you got any selected item in your ListBox?
MessageBox.Show(listbox1.SelectedValue != null ? listbox1.SelectedValue.ToString() : "I have 0 selected item!");
Edit(based on your comment).-
Inside your Selection_Changed event write this:
if (listbox1.SelectedItem!=null)
{
MessageBox.Show(listbox1.Items.CurrentItem.ToString());
MessageBox.Show(listbox1.SelectedItem.ToString()); MessageBox.Show(listbox1.SelectedValue != null ? listbox1.SelectedValue.ToString() : "I have 0 selected item!");
}
Another approach. This going to work!
if (listbox1.SelectedItem!=null)
{
DataRowView d1=listbox1.SelectedItem as DataRowView;
MessageBox.Show(d1["department_id"].tostring());
}
Hope it helps.