Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

listbox item click event?

i binded some items to listbox.whenever click on particular listitem i want to display that subitems in another page.

Please tell me how to acheive this.

how to get the listitem id whenever click on particular list item ?

like image 201
Sravanti Avatar asked Aug 03 '11 10:08

Sravanti


2 Answers

To clarify (in case you don't feel like creating a new DataBound application and just want the answer), instead of depending on the click event for a listbox item, you should be looking at the selectionchanged event for the list box itself.

eg:

<ListBox SelectionChanged="MainListBox_SelectionChanged">


// Handle selection changed on ListBox
private void MainListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    // If selected index is -1 (no selection) do nothing
    if (MainListBox.SelectedIndex == -1)
        return;

    // Navigate to the new page
    NavigationService.Navigate(new Uri("/DetailsPage.xaml?selectedItem=" + MainListBox.SelectedIndex, UriKind.Relative));

    // Reset selected index to -1 (no selection)
    MainListBox.SelectedIndex = -1;
}
like image 55
Henry C Avatar answered Oct 12 '22 13:10

Henry C


Look at the code created as part of a new DataBound application. It does just this.

like image 24
Matt Lacey Avatar answered Oct 12 '22 14:10

Matt Lacey