• 大小: 59KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-14
  • 语言: C#
  • 标签: DataGridView  委托  

资源简介

两个DataGridView通过委托实时传值,安全高效 C# 两个窗体之间实时传递数据的实例。利用委托和事件的方法,从子窗体传送数据到主窗体。比较安全。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender EventArgs e)
        {
            Form2 frm = new Form2();
            frm.RowAdded += new Form2.AddRow(AddRow);
            frm.ShowDialog();


        }

        public void AddRow(DataGridViewRow dgvr)
        {
            int i = dataGridView1.Rows.Add();
            foreach (DataGridViewColumn col in dataGridView1.Columns)
            {
                if (dgvr.DataGridView.Columns.Contains(col.Name))
                {
                    dataGridView1.Rows[i].Cells[col.Name].Value = dgvr.Cells[col.Name].Value;
                }

            }
        }

    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-09-10 18:25  WindowsFormsApplication2\
     目录           0  2019-09-10 18:25  WindowsFormsApplication2\.vs\
     目录           0  2019-09-10 18:25  WindowsFormsApplication2\.vs\WindowsFormsApplication2\
     目录           0  2019-09-10 18:25  WindowsFormsApplication2\.vs\WindowsFormsApplication2\v14\
     文件       35328  2019-09-10 18:47  WindowsFormsApplication2\.vs\WindowsFormsApplication2\v14\.suo
     目录           0  2019-09-10 18:46  WindowsFormsApplication2\WindowsFormsApplication2\
     文件        1039  2019-09-10 18:25  WindowsFormsApplication2\WindowsFormsApplication2.sln
     目录           0  2019-09-10 18:26  WindowsFormsApplication2\WindowsFormsApplication2\bin\
     目录           0  2019-09-10 18:44  WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\
     文件       12288  2019-09-10 18:46  WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.exe
     文件       26112  2019-09-10 18:46  WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.pdb
     文件       22688  2019-09-10 18:46  WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.vshost.exe
     目录           0  2019-09-10 18:26  WindowsFormsApplication2\WindowsFormsApplication2\bin\Release\
     文件        1016  2019-09-10 18:44  WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs
     文件        4099  2019-09-10 18:44  WindowsFormsApplication2\WindowsFormsApplication2\Form1.Designer.cs
     文件        6369  2019-09-10 18:44  WindowsFormsApplication2\WindowsFormsApplication2\Form1.resx
     文件         650  2019-09-10 18:46  WindowsFormsApplication2\WindowsFormsApplication2\Form2.cs
     文件        3546  2019-09-10 18:46  WindowsFormsApplication2\WindowsFormsApplication2\Form2.Designer.cs
     文件        6369  2019-09-10 18:46  WindowsFormsApplication2\WindowsFormsApplication2\Form2.resx
     目录           0  2019-09-10 18:25  WindowsFormsApplication2\WindowsFormsApplication2\obj\
     目录           0  2019-09-10 18:46  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\
     文件         864  2019-09-10 18:25  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        7042  2019-09-10 18:27  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     目录           0  2019-09-10 18:25  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\TempPE\
     文件        1397  2019-09-10 18:46  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.csproj.FileListAbsolute.txt
     文件        1070  2019-09-10 18:46  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.csproj.GenerateResource.Cache
     文件        2210  2019-09-10 18:44  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.csprojResolveAssemblyReference.cache
     文件       12288  2019-09-10 18:46  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.exe
     文件         180  2019-09-10 18:44  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.Form1.resources
     文件         180  2019-09-10 18:46  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.Form2.resources
     文件       26112  2019-09-10 18:46  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.pdb
............此处省略9个文件信息

评论

共有 条评论