WPF DataGrid选择列放入列

时间:2015-02-14 21:03:01

标签: c# wpf datagrid

我想将DataGrid所选行的所有属性放到文本框中。 如何将所选行的每个数据放入文本框?

<DataGrid x:Name="dgSearch" ItemsSource="{Binding}" IsReadOnly="True" Height="390" Width="Auto" MouseLeftButtonDown="dgSearch_MouseLeftButtonDown"/>

img

1 个答案:

答案 0 :(得分:0)

要获得所选行,您有两个选择:

1-将DataGridRow用于所选行

2-将选定的行投射到相应的模型

1:

DataRowView Row = (DataRowView)dataGridView.SelectedItem;
//Then 
var i = Row["Column Name"];
//Then putting to you text box

2:

CorrespondingModel model = (CorrespondingModel)dataGridView.SelectedItem;
// Then 
textBox.Text = model.PropertyX + model.ProprtyY;