我在form1中有一个文本框,并且我在form2中有一个datagridview,那么如何在datagridview列中将form1 texboxes值传递给form2 [英] I have a textboxes in form1 as well as I have a datagridview in form2 then how can I pass the form1 texboxes values to form2 in datagridview columns

查看:50
本文介绍了我在form1中有一个文本框,并且我在form2中有一个datagridview,那么如何在datagridview列中将form1 texboxes值传递给form2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个疑问,请你告诉我编码,我在form1(数据网格视图列)中有一个文本框以及我在form2中有数据网格视图然后如何传递/添加form1文本框(列的数据网格视图)datagridview columns中form2的值。请你帮我一下这个代码



我试过的:



form1:

命名空间PO 
{
公共部分类Adding_Items:表格
{

public Adding_Items()
{
InitializeComponent();
}

private void button1_Click(object sender,EventArgs e)
{
if(textBox1.Text!=& textBox2.Text!= & textBox3.Text!=& textBox4.Text!=& textBox5.Text!=)
{
Po f2 = new Po();
f2.Show();
}

}

private void button2_Click(object sender,EventArgs e)
{
if(textBox1.Text!= & textBox2.Text!=& textBox3.Text!=& textBox4.Text!=& textBox5.Text!=)
{



}
}
}
}

解决方案

请看这里:在两个表单之间传输信息,第1部分:父母对孩子 [ ^ ]


将值从一个表单传递给另一个表单

 Po f2 =  new  Po(textBox1.Text); 
f2.Show();
第二种形式
public Po( string a)
{
InitializeComponent();
label1.Text = a;
}

DataTable dt = new DataTable();
private void Form1_Load( object sender,EventArgs e)
{
dt.Columns.Add(label1.Text);
dataGridView1.DataSource = dt;
// dt.Columns.Add();
// dt.Columns.Add();
}


I have a doubt can you please tell me coding, I have a textbox in form1(columns of data grid view) as well as I have data grid view in form2 then how can I pass/add the form1 textboxes(columns of data grid view) values to form2 in datagridview columns.can you please help me with the code

What I have tried:

form1:

namespace PO
{
    public partial class Adding_Items : Form
    {
       
        public Adding_Items()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "" & textBox2.Text != "" & textBox3.Text != "" & textBox4.Text != "" & textBox5.Text != "")
            {
                 Po f2 = new Po();
                f2.Show();
            }
          
        }

        private void button2_Click(object sender, EventArgs e)
        {
     if (textBox1.Text != "" & textBox2.Text != "" & textBox3.Text != "" & textBox4.Text != "" & textBox5.Text != "")
            {
                
                
          
}
        }
    }
}

解决方案

See here: Transferring information between two forms, Part 1: Parent to Child[^]


Pass the value from one form to another

Po f2 = new Po(textBox1.Text);
 f2.Show();
In second form
public Po(string a)
        {
            InitializeComponent();
           label1.Text=a;
        }

DataTable dt=new DataTable();
private void Form1_Load(object sender, EventArgs e)
        {
            dt.Columns.Add(label1.Text);
dataGridView1.DataSource = dt;
            //dt.Columns.Add("");
           // dt.Columns.Add("");
        }


这篇关于我在form1中有一个文本框,并且我在form2中有一个datagridview,那么如何在datagridview列中将form1 texboxes值传递给form2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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