2
我的問題是我想設置selectedItem(在數據網格中標記一行)。 我搜索了很多,其實我希望有一個更好的解決方案,而不是迭代通過數據網格。WPF DataGrid set selectedItem
我的建議:
我有值3的數,我想的DataGrid行與3號標.. 我這個嘗試之一:
DataGridRow row = (DataGridRow)gridErrors.ItemContainerGenerator.ContainerFromItem(gridErrors.SelectedItem);
if (row != null)
{
ErrorInfo info = row.Item as ErrorInfo;
var blubb = from c in this.objectsToSync
where c.Number == info.Number
select c;
if (blubb != null)
{
gridCsvContent.SelectedItem = blubb;
gridCsvContent.ScrollIntoView(blubb);
DataGridRow rowContent = (DataGridRow)gridCsvContent.ItemContainerGenerator.ContainerFromItem(gridCsvContent.SelectedItem);
rowContent.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
}
}
首先我提取DataGridRow其中我的號碼是從(值3) 然後我有一個linq查詢,我得到的對象編號爲3. 然後我想設置selectedItem,但它後爲空。
有沒有解決方案,我不必遍歷數據網格..? 有沒有辦法直接設置選定的項目?
非常感謝您提前! kr