How to pull selected row-column value

Aug 21, 2008 at 3:49 AM
Hello all,

I am using the datagrid to show a list of program users.  When you click on a row I catch the click using 


I then am trying to get the value from the username field in the datagrid.  The columns are automatically populated and the itemssource is the product of a  linq to sql source

I am able to pull the row collection by using the datagrid's selecteditem property, but I have not been able to figure out how to loop through the collection to collect the value of the username.

Any help is appreciated

Aug 21, 2008 at 5:19 AM
When you say row collection, do you mean the object returned from DataGrid.SelectedItem?  If so, you have access to the whole object with just that.  If you want to go through the UI, you do have access to this property: 



abstract class DataGridColumn : DependencyObject
    public FrameworkElement GetCellContent(object dataItem)

Is this along the lines of what you're looking for?


Aug 22, 2008 at 2:55 PM
Edited Aug 22, 2008 at 2:56 PM
Something like this?

(DataGrid.SelectedItem == null) return;
string userID = (string)(((DataRowView)(DataGrid.SelectedItem)).Row[1]); 

//This would work if 'user id' is in column [1].

Not sure if that is what you are asking for?



Aug 24, 2008 at 1:22 PM
rams, sadly this was the result

Unable to cast object of type '<>f__AnonymousType1`6[System.String,System.String,System.String,System.String,System.String,System.Nullable`1[System.DateTime]]' to type 'System.Data.DataRowView'