将数据从1个DataGrid添加到另一个DataGrid [英] Adding Data from 1 DataGrid to Another DataGrid

查看:51
本文介绍了将数据从1个DataGrid添加到另一个DataGrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我的代码如下,但是当我点击datagrid 1中的一个项目时,它只会在datagrid2上显示一个空白行 - 没有文字:(



Hi I have my code as follows but when i click on an item in datagrid 1 it only brings up a blank row on datagrid2 - no text :(

<DataGrid.Columns>
    <DataGridTextColumn Width="200" Header="colS" />
    <DataGridTextColumn Width="200" Header="colA"  />
    <DataGridTextColumn Width="1" Header="colF"   />
</DataGrid.Columns>










private void SongDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
     if (SongDataGrid.SelectedIndex >= 0)
    {

        var i = SongDataGrid.SelectedIndex.ToString();
        System.Data.DataRowView lbi = (System.Data.DataRowView)SongDataGrid.SelectedValue;
        var SongName = (lbi.Row[0].ToString());
        var ArtistName = (lbi.Row[1].ToString());
        var FileLocation = (lbi.Row[2].ToString());
        myPlayList.Items.Add(new { colS = SongName, colA = ArtistName, colF = FileLocation });







欢呼



Tony




cheers

Tony

推荐答案

参考类似解决的QA:如何根据另一个数据网格的选择填充一个WPF Datagrid [ ^ ]



另一个类似的讨论:

从一个动态复制列wpf datagrid到另一个 [ ^ ]
Refer similar solved QA: How to fill one WPF Datagrid based on selection of another datagrid[^]

Another similar discussion:
Copying columns dynamically from one wpf datagrid to another[^]


您好,



您可以实现以下功能。



1.使用第一个datagrid的列定义新的DataTable。



2.在第一个datagrid1的选定项更改事件中,绑定每个列数据已经声明为datatble。



3.将数据表绑定到第二个数据网格。



是这个帮助满员,或者你想要任何帮助吗?



问候,

Kiran。
Hi ,

you can achieve the functionality as follows.

1. define the new DataTable with columns of first datagrid.

2. in the selected item change event of first datagrid1 ,bind the each column data to already declared datatble.

3. Bind the datatable to second datagrid.

is this help full, or do you want any help?

Regards,
Kiran.


全部谢谢为了你的帮助 - 一切工作都很棒



欢呼



Tony
Thanks all for your help - all working great

cheers

Tony


这篇关于将数据从1个DataGrid添加到另一个DataGrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆