C# WPF Datagrid: Get value from SelectionChanged event -


This is driving me crazy all day. I just want the value of the selected row in a datagrid, it works in VB.net, I'm new to a small c # and I can not get it to work.

VB is in my work code:

  Private sub dg_qc_SelectionChanged (ByVal as the object, byVal e System.Windows.Controls.SelectionChangedEventArgs) as TempListItem As QCProperties = CTYPE (Sender, Data Grid) .SelectedItem is in dim temp1 string = TempListItem.PartNumber End Sub   

I have in C #:

 < Code> Private Zero dg_blockList_SelectionChanged (Object Sender, System.Windows.Controls.SelectionChangedEventArgs e) {dgProperties tempItems = ((DataGrid) Sender). Selected item; String tempModel = tempItems.modelRev; String tempDate = tempItems.date; }   

I can change the error "indirect type, not the" my property class "for the object (if you are missing a cast?)

I have searched the Internet and I have had some luck, I know it easily from them. Please help.

Thanks, Chelsey

< Div class = "after" text "itemprop =" text ">

You just need to correctly select SelectedItem to cast: as dgProperties

  dgProperties tempItems = (( Data grid) Analyst) .SelectedItem;   

Note that you Temptitms! = NULL should check the exact before reaching the reset of the model and date.

Comments