【问题标题】:WPF DataGrid selected row put in listWPF DataGrid 选定的行放入列表
【发布时间】:2015-02-14 21:03:01
【问题描述】:

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

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

img

【问题讨论】:

    标签: c# wpf datagrid


    【解决方案1】:

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

    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;
    

    【讨论】:

    • 1.Error :Cannot Apply indexing with [] to an expression of type 'System.Windows.Controls.DataGridRow'
    • @user3793233:抱歉,我不小心输入了错误的类型。检查更新。
    猜你喜欢
    • 2011-04-24
    • 2011-05-31
    • 2013-03-10
    • 2010-12-30
    • 2011-06-07
    • 2013-02-03
    • 2020-12-14
    • 2018-04-24
    • 1970-01-01
    相关资源
    最近更新 更多