Datagridview选择了传递给另一个form2文本框的行 [英] Datagridview selected row passing to another form2 textboxes

查看:57
本文介绍了Datagridview选择了传递给另一个form2文本框的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我需要你的帮助。我有两个表格。 Form1中有一个Datagridview,Form2中有5个单元文本框。我的问题是:当我在datagridview中选择单元格时,如何传递值Form2文本框



Hi Everyone. I need you help. I have a two form. there is a Datagridview in Form1 and there is 5 units textbox in Form2. My question is: when i selected cell click in datagridview, How to Pass Values Form2 textboxes

推荐答案

您好,请在发布问题之前先做一些研究!



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



祝你好运
Hi, try making some resarch before posting questions!

Passing Data Between Forms[^]

Good luck


public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            dataGridView1.Rows.Add( 1,2);
        }
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == -1 )
            {
                try
                {
                    Form2 f2 = new Form2();
                    f2.dgvr = dataGridView1.Rows[e.RowIndex];
                    f2.Show();
                }
                catch (Exception er)
                {
                    MessageBox.Show(er.Message.ToString());
                }
            }
        }
    }




public partial class Form2 : Form
    {
        public DataGridViewRow dgvr;
        public Form2()
        {
            InitializeComponent();
        }
        private void Form2_Load(object sender, EventArgs e)
        {
            textBox1.Text = dgvr.Cells[0].Value.ToString();
            textBox2.Text = dgvr.Cells[1].Value.ToString();
        }
    }


这篇关于Datagridview选择了传递给另一个form2文本框的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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