I am beginner in WPF. I am trying to read Datagrid Selected Items with DataRow/DataRowView. My code is following--
foreach (System.Data.DataRowView row in dgDocument.SelectedItems)
{
txtPhotoIDNo.Text = row["PhotoIdNumber"].ToString();
}
but I am facing the following error--
"Unable to cast object of type '<>f__AnonymousTypeb
11[System.String,System.Byte,System.String,System.String,System.String,System.Byte[],System.Nullable
1[System.DateTime],System.String,System.Nullable`1[System.DateTime],System.String,System.String]' to type 'System.Data.DataRowView'."
When I am trying with following Way, that works fine-
(dgDocument.SelectedCells[2].Column.GetCellContent(item) as TextBlock).Text;
The problem is when I required to add a new column/change the datagrid column position, I required to change index for entire assigned value. To cover this problem, I want to assign value with the above mentioned way with column Name.