private void ListBox_SelectedIndexChanged(object sender, RoutedEventArgs e)//event of researcher list { //disable 'showname'btn,'cumulative count'btn and datagrid before user select a record btn1.IsEnabled = true; btn2.IsEnabled = true; datagrid1.IsEnabled = true; list2.ItemsSource = P_list; //r_details.GotFocus = true; //filter function bug here if (list1.SelectedIndex != -1) //if user selected a listitem and use filter function,application will be crushed { BitmapImage b = new BitmapImage(); //Generate avatar b.BeginInit(); b.UriSource = new Uri(@rlist[list1.SelectedIndex].photo.ToString()); b.EndInit(); avatar.Source = b; //show details of specific researcher ContentControl1.Content = ResearcherDetail.showdetail(rlist[list1.SelectedIndex].id, rlist, position_list, researcher_publication_list, publication_list, btn1); datagrid1.ItemsSource = null; //reset datagrid tbk_name.Text = ""; //reset show name global_id = rlist[list1.SelectedIndex].id;//set grobal value for id P_list = PublicationList.generate_P_list(rlist[list1.SelectedIndex].id, researcher_publication_list, publication_list); Orgin_list = P_list; list2.ItemsSource = P_list; list2.Items.Refresh(); tab_m.SelectedIndex = 1;//auto jump to tab 2 } }