我想将DataGrid
所选行的所有属性放到文本框中。
如何将所选行的每个数据放入文本框?
<DataGrid x:Name="dgSearch" ItemsSource="{Binding}" IsReadOnly="True" Height="390" Width="Auto" MouseLeftButtonDown="dgSearch_MouseLeftButtonDown"/>
答案 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;