以其他形式将数据从datagridview发送到datagridview [英] send data from datagridview to datagridview in other form

查看:92
本文介绍了以其他形式将数据从datagridview发送到datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能将数据从Form2中的datagrid转换为c#中其他形式的datagrid?

How can i get data from datagrid in form2 to datagrid in other form in c#?

推荐答案

^ ]


采取一种形式form1,采用第二种形式,我命名为FormDestination,输入id为dataGridDest的datagridcotrol(第二种形式,FormDestination)

将以下代码写在from1按钮中,点击

Take one form form1,take second form i named as FormDestination ,put a datagridcotrol with id as dataGridDest in second form (FormDestination)

Write the below code in from1 button click

private void button1_Click(object sender, EventArgs e)
       {
           FormDestination formDest = new FormDestination();  //FromDestination is my seconcd form

           DataTable tableemp = new DataTable();

           using (SqlConnection con = new SqlConnection("user id=sa;password=just4fun;database=sdp;data source=SITT244"))  //Thease are your sql server credentials
           {
               using (SqlCommand cmd = new SqlCommand("select * from emp",con))
               {
                   SqlDataAdapter da = new SqlDataAdapter(cmd);
                   da.Fill(tableemp);
               }
           }

           Control[] ctlgrid = formDest.Controls.Find("dataGridDest", true);  //Finding the dataGridDest in form name as FormDestination

           DataGridView grid =(DataGridView) ctlgrid[0];   //Converting the control array to grid control

           grid.DataSource = tableemp;
           formDest.Show(); //Callling the second form from first Form


       }



以相同的方式将数据以哪种形式从哪个表绑定到datagrid,将相同的表分配给FormDestination中的datagrid



From which table you bind data to datagrid in first form in the same way assign the same table to datagrid in FormDestination


这篇关于以其他形式将数据从datagridview发送到datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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