I guess, I have problem with threading in C#/WPF .
How to run a method right after another one for prevent some problem like Null Value .
I think in this below code "IF statment" run before "selectLessonContent(selectedLessonId)" method and cause a Null Value problem in below.
when I use MessageBox.Show() right after selectLessonContent(selectedLessonId) method this problem gone.
private void btnSelectLesson_Click(object sender, ExecutedRoutedEventArgs e)
{
selectLessonContent(selectedLessonId);
if (selectedUserID != "QuickStart")
{
int lessonScore = Int32.Parse(userlessonManager1.selectUserLesson("existCheck", selectedUserID, selectedLessonId).Rows[0][3].ToString());
if (lessonScore < sectionListview.Items.Count )
{
for (int a = 1; a < sectionListview.Items.Count; a++)
{
ListViewItem item = sectionListview.ItemContainerGenerator.ContainerFromIndex(a) as ListViewItem;
ContentPresenter templateParent = GetFrameworkElementByName<ContentPresenter>(item);
DataTemplate dataTemplate = sectionListview.ItemTemplate;
//error occured Here : Value cannot be null.
Button btnTemp = dataTemplate.FindName("btnSectionList", templateParent) as Button;
btnTemp.IsEnabled = false;
}
}
}
}