我已經實現了一個簡單的搜索函數,該函數根據搜索查詢在DataGrid中突出顯示一行。它的要點如下:在排序時搜索DataGrid
public bool scrollToSearch(string query) {
dataGrid.SelectedItems.Clear();
for (; searchIndex < registrants.Count; searchIndex++) {
foreach (string field in registrants[searchIndex]) {
if (field.ToLower().Contains(query)) {
dataGrid.SelectedItem = registrants[searchIndex];
dataGrid.ScrollIntoView(registrants[searchIndex]);
searchIndex++;
return true;
}
}
}
}
它搜索列表匹配,則突出顯示(選擇)該行和它滾動到視圖中。問題是,當對DataGrid進行排序時,搜索將突出顯示一個看似隨機的行而不是第一個結果,因爲它正在搜索原始未排序列表。有沒有辦法讓我在排序列表中搜索它?
檢出[this](http://stackoverflow.com/questions/8896422/persist-sorting-from-datagrid-to-itemssource-collection) – 2012-04-20 00:40:41