Answer the question
In order to leave comments, you need to log in
What about type conversion?
Good day!
I need to know which row I selected on click in the DateGrid,
private void DGMaterials_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
DataRowView row = (DataRowView)dGMaterials.SelectedItem;
MessageBox.Show(" ID: " + row["Id"]);
}
Could not cast object type 'DemoExam2018.ViewModel.OrderingMaterialsPageViewModel' to type 'System.Data.DataRowView'
Answer the question
In order to leave comments, you need to log in
(DataRowView)dGMaterials.SelectedItem;
!!!
https://docs.microsoft.com/en-us/dotnet/csharp/pro...
Well, if you need it straight from the shoulder, then:
private void DGMaterials_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
DataGrid grid = sender as DataGrid;
if (grid != null && grid.SelectedItems != null && grid.SelectedItems.Count == 1)
{
DataGridRow dgr = grid.ItemContainerGenerator.ContainerFromItem(grid.SelectedItem) as DataGridRow;
DataRowView row = (DataRowView)dgr.Item;
MessageBox.Show(" ID: " + row["Id"]);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question