当我输入只返回一行的搜索条件时,我无法触发OnSelectionChanged事件listbox在任何其他时间按预期工作。
有人知道解决方案吗?这样我就可以更改所选项目了!!请帮帮我
private void lstShedBatch_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
try{
if (lstShedBatch.SelectedItem != null && lstShedBatch.SelectedIndex != -1)
{
ShedBatch currShedBatch = (ShedBatch)this.ShedBatchView.CurrentItem;
Window1.ShedBatchId = currShedBatch.ShedBatchId;
Window1.selectedShedId = currShedBatch.ShedId;
RoutedEventArgs args = new RoutedEventArgs(selectShedBatchClickEvent);
RaiseEvent(args);
}
}
catch
{
}
}
如上所述的问题是,如果列表中的项数=0或1,则不会触发此事件。如果有一条记录,我想知道它是什么,并使用它传递变量。