selecteditem

Get selected row item in DataGrid WPF

佐手、 提交于 2019-11-26 02:08:13
问题 I have a DataGrid , bound to Database table, I need to get the content of selected row in DataGrid , for example, I want to show in MessageBox content of selected row. Example of DataGrid : So, if I select the second row, my MessageBox has to show something like: 646 Jim Biology . 回答1: You can use the SelectedItem property to get the currently selected object, which you can then cast into the correct type. For instance, if your DataGrid is bound to a collection of Customer objects you could

Data binding to SelectedItem in a WPF Treeview

时光毁灭记忆、已成空白 提交于 2019-11-25 22:47:39
问题 How can I retrieve the item that is selected in a WPF-treeview? I want to do this in XAML, because I want to bind it. You might think that it is SelectedItem but apparently that does not exist is readonly and therefore unusable. This is what I want to do: <TreeView ItemsSource=\"{Binding Path=Model.Clusters}\" ItemTemplate=\"{StaticResource ClusterTemplate}\" SelectedItem=\"{Binding Path=Model.SelectedCluster}\" /> I want to bind the SelectedItem to a property on my Model. But this gives me