如何将一个数据网格的选定行移动到另一个数据网格中 [英] How to move selected rows of one datagrid into another one

查看:115
本文介绍了如何将一个数据网格的选定行移动到另一个数据网格中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

数据网格标题的顺序为Filename,FileExtension和FilePath。

我通过设置 SelectionMode =Extended来启用xaml中的多个行选择



C#代码



Both the datagrid headers are in the order as Filename, FileExtension and FilePath.
I have enabled multiple selection of rows in xaml by setting SelectionMode="Extended".

C# code

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;


namespace FileListGrabber
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            MyWindow_Loaded();
        }

        private void MyWindow_Loaded()
        {
            // Here I am fetching data from a CSV file
            var reader = new StreamReader(File.OpenRead(@"C:\BigB.csv"));

            // List to store data fetched from CSV file
            List<GetFile> Fetcher = new List<GetFile>();


            while (!reader.EndOfStream)
            {
                var line = reader.ReadLine();
                string[] values = line.Split(',');

                Fetcher.Add(new GetFile
                {
                    FileName = values[0],
                    FileExtension = values[1],
                    FilePath = values[2]
                }
                );
            }
            myGridView1.ItemsSource = Fetcher;
        }
        
        public class GetFile
        {
            public string FileName
            {
                get;
                set;
            }

            public string FileExtension
            {
                get;
                set;
            }

            public string FilePath
            {
                get;
                set;
            }
        }

        private void buttonRight_Click(object sender, RoutedEventArgs e)
        {
            // Code to move row in myGridView2
        }
        private void buttonLeft_Click(object sender, RoutedEventArgs e)
        {
            // Code to move row in myGridView1
        }
    }
}

推荐答案

想一想!这很简单。需要两个列表(类型 GetFile ):1。对于源dgv和2.对于目标dgv。

从第一个dgv获取数据到 GetFile class,添加到第二个列表并从第一个列表中删除。

试试!
Think of it! It's quite simple. There are needed two lists (type of GetFile): 1. for source dgv and 2. for destination dgv.
Fetch data from first dgv into GetFile class, add to the second list and remove from first one.
Try!


这篇关于如何将一个数据网格的选定行移动到另一个数据网格中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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