将值传递给另一种形式的c #windows应用程序中的datagridview [英] Passing values to datagridview in another form c# windows application

查看:74
本文介绍了将值传递给另一种形式的c #windows应用程序中的datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我真的想知道如何将整个datagridview值传递给另一种形式的另一个datagridview?使用c#windows应用程序。



i有两种形式,



form1:

i有一个搜索选项有,

一个文本框和一个搜索按钮,

当我输入与表格字段相关的内容时我的文本框和点击搜索按钮,



相应的数据已经显示到另一个表格datagridview,这意味着form2。



form2:



i只有datagridview。



please我的代码见下面,我错了我的代码,请让我知道解决方案..



我的代码是:





form1:



  private   void  button1_Click( object  sender,EventArgs e)
{
尝试
{
if (textBox1.Text ==
{
MessageBox.Show( 请输入输入键。 错误信息);
}
else
{
DataTable dataTable = new DataTable();
con = new SqlConnection(s);
con.Open();
cmd = new SqlCommand( 选择目的地,TimeofDay,DialCode,EffectiveDate,来自RateSheets的NewOffer,其中Destinations =' + textBox1.Text + ' ,con);
SqlDataReader sqlDataReader = cmd.ExecuteReader();
dataTable.Load(sqlDataReader);
con.Close();
form2 fm = new testing();

fm.Show();
dataGridView1.DataSource = dataTable;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString( ));
}
}



提前谢谢...

解决方案

这里好是一些如何在表单之间传递值的链接:



在.NET 1.x中的表单之间传递值与C#和VB.NET示例 [ ^ ]

使用代表在两个表单之间传递数据 [ ^ ]

在Windows窗体之间传递数据 [ ^ ]

在表单之间传递数据 [ ^ ]



祝你好运,

OI

Hello all,

I really want to know how can I pass a whole datagridview values to another datagridview in another form? using c# windows application.

i have two form ,

form1:
i have one search option which is have,
one text box and one search button,
when i type something related to the table field in my text box and click search button,

the corresponding data has displayed to another form datagridview, that means form2.

form2:

i have only datagridview.

please my code see below where i did mistake my code and let me know the solution please..

my code is:


form1:

private void button1_Click(object sender, EventArgs e)
{
      try
      {
            if (textBox1.Text == "")
            {
                 MessageBox.Show("Please Enter the Input Key.", "Error Message");
            }
            else
            {
                 DataTable dataTable = new DataTable();
                 con = new SqlConnection(s);
                 con.Open();
                 cmd = new SqlCommand("select Destinations,TimeofDay,DialCode,EffectiveDate,NewOffer from RateSheets where Destinations='" + textBox1.Text + "'", con);
                 SqlDataReader sqlDataReader = cmd.ExecuteReader();
                 dataTable.Load(sqlDataReader);
                 con.Close();
                 form2 fm = new testing();
           
                 fm.Show();
                 dataGridView1.DataSource = dataTable;
             }                   
       }                   
       catch (Exception ex)
       {
             MessageBox.Show(ex.ToString());
       }
}


Thanks in advance...

解决方案

Well here are some links for how you can pass values between forms:

Passing Values between Forms in .NET 1.x with C# and VB.NET examples[^]
Using a delegate to pass data between two forms[^]
Passing Data between Windows Forms[^]
Passing Data Between Forms[^]

Good luck,
OI


这篇关于将值传递给另一种形式的c #windows应用程序中的datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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