2 つのエントリを含む wpf アプリケーションに listBox を作成しました。私はそれのためにダブルクリックイベント関数を書きました.しかし、単一のエントリをクリックすると、それが表示されますNullReferenceException
. 例外は次の行にあります -if (listBox1.SelectedItem != null)
クリックする単一のエントリが必要です。どのように進めればよいですか?
私のダブルクリックイベントは次のとおりです。
private void listBox1_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
//Submit clicked Entry
if (listBox1.SelectedItem != null)
{
Harvest_TimeSheetEntry entryToPost = (Harvest_TimeSheetEntry)listBox1.SelectedItem;
if (!entryToPost.isSynced)
{
//Check if something is selected in selectedProjectItem For that item
if (entryToPost.ProjectNameBinding == "Select Project")
MessageBox.Show("Please Select a Project for the Entry");
else
Globals._globalController.harvestManager.postHarvestEntry(entryToPost);
}
else
{
//Already synced.. Make a noise or something
MessageBox.Show("Already Synced;TODO Play a Sound Instead");
}
}
else
{
throw new NullReferenceException("Entry does not exist");
}
}
イベントハンドラを次のように割り当てます。
InitializeComponent();
listBox1.MouseDoubleClick += new MouseButtonEventHandler(listBox1_MouseDoubleClick);