DataGrid에 대한 간단한 데이터 바인딩을 수행했습니다. 이제 행을 클릭하면 DataGrid에서 관련 rowdata (전체 행 데이터)를 얻고 싶습니다. 행 선택 이벤트가 없으므로 마우스 키보드를 사용해야합니까?.Datagrid 행 선택 이벤트, WPF
0
A
답변
0
private void dataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ProductItem productItem = (ProductItem)dataGrid.SelectedItem; //Datagrid bound with ProductItem
}
1
나는 이렇게했다. 다른 것들은 더 간단한 방법 일 수 있습니다! Mine은 Mediaplayer에 대한 PlayListEntries 클래스의 Observable Collection을 처리합니다. 도움이 되었으면 좋겠다.
private void PlayList_OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
DependencyObject dep = (DependencyObject)e.OriginalSource;
// iteratively traverse the visual tree
while ((dep != null) && !(dep is DataGridCell) && !(dep is DataGridColumnHeader))
{
dep = VisualTreeHelper.GetParent(dep);
}
if (dep == null)
return;
if (dep is DataGridColumnHeader)
{
DataGridColumnHeader columnHeader = dep as DataGridColumnHeader;
// do something
}
if (dep is DataGridCell)
{
DataGridCell cell = dep as DataGridCell;
// navigate further up the tree
while ((dep != null) && !(dep is DataGridRow))
{
dep = VisualTreeHelper.GetParent(dep);
}
DataGridRow row = dep as DataGridRow;
var ple = (PlayListEntry)row.Item;
// From here you have access to all of the row.
// Each column is suitable bound.
// I can post the xaml if you are not sure.
//object value = ExtractBoundValue(row, cell); //4
//int columnIndex = cell.Column.DisplayIndex;
//int rowIndex = FindRowIndex(row);
//var s = string.Format("Cell clicked [{0}, {1}] = {2}",rowIndex, columnIndex, value.ToString());
}
}
관련 문제
- 1. WPF DataGrid 행 선택 문제
- 2. DataGrid (wpf)에서 행 인덱스 선택
- 3. Datagrid 행 선택 단추 클릭 WPF 있음
- 4. WPF DataGrid DataGrid.RowDetailsTemplate에서 행 선택 취소
- 5. GWT DataGrid 행 선택
- 6. WPF DataGrid 선택
- 7. WPF DataGrid 행 문제
- 8. WPF DataGrid 행 높이
- 9. WPF DataGrid : 행 재정렬?
- 10. WPF DataGrid 빈 행
- 11. WPF Datagrid 행 번호
- 12. Datagrid 행 (WPF) 삭제
- 13. WPF Datagrid : Loading_Completed 이벤트?
- 14. WPF DataGrid CellEditEnded 이벤트
- 15. Asp.Net DataGrid 행 선택된 이벤트
- 16. wpf datagrid mvvm friendly에서 행 선택 및 선택 취소
- 17. 자동 선택 DataGrid 행
- 18. WPF DataGrid 행 추가 codebehind
- 19. WPF 액세스 DataGrid 행 요소
- 20. WPF Datagrid 행 색상 변경
- 21. WPF DataGrid : 행 당 리소스?
- 22. 스크롤하는 가상 행 WPF Datagrid
- 23. WPF DataGrid 행의 행 번호
- 24. WPF DataGrid 바닥 글 행
- 25. Wpf Datagrid 행 삭제 문제
- 26. wpf DataGrid 행 전경 코드에서
- 27. WPF DataGrid 전체 행 편집
- 28. WPF Datagrid 행 유효성 검사
- 29. WPF Datagrid - 단일 행 강제로
- 30. WPF DataGrid 행 오류 숨기기