如何从datagridview单元更新表单1中存在的数据进入表单2中的事件? [英] How can do update of data present in form 1 from datagridview cell enter event of form 2 ?

查看:70
本文介绍了如何从datagridview单元更新表单1中存在的数据进入表单2中的事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在.net Windows应用程序中创建一个表单.只需看下面的代码即可.这些代码用于更新过程.

Hi,

I am creating a form in .net windows application. Just watch the below codes.These codes for update process.

 private void imgbtnUpdate1_Click(object sender, EventArgs e)
        {
            if ((txtPhoneNo.Text != "") && (dtpDateofRecharge.Text != "") && (cmbOperator.Text != "") && (txtAmount.Text != ""))
            {
                DialogResult dr = MessageBox.Show("Do you Want to Update?","Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
                if (dr == DialogResult.Yes)
                {
                    con.Open();
                    SqlCommand cmd = new SqlCommand("update phonebill set PhoneNo='"+txtPhoneNo.Text+"',DateOfRecharge='"+dtpDateofRecharge.Value+"',
Operator='"+cmbOperator.Text+"',Amount='"+txtAmount.Text+"' where PhoneNo='"+txtPhoneNo.Text+"'",con);
                    cmd.ExecuteNonQuery();
                    con.Close();
                    MessageBox.Show("Updated Successfully","Information",MessageBoxButtons.OK,MessageBoxIcon.Information);                                      
                }
            }
        }





private void dgvPhone_CellEnter(object sender, DataGridViewCellEventArgs e)
       {
           txtPhoneNo.Text=dgvPhone.Rows[e.RowIndex].Cells["PhoneNo"].Value.ToString();
           dtpDateofRecharge.Text=dgvPhone.Rows[e.RowIndex].Cells["DateOfRecharge"].Value.ToString();
           cmbOperator.Text=dgvPhone.Rows[e.RowIndex].Cells["Operator"].Value.ToString();
           txtAmount.Text=dgvPhone.Rows[e.RowIndex].Cells["Amount"].Value.ToString();
       }




现在我的问题是,如果我在表格2中使用datagridview,如何通过使用单元格输入事件将这些数据放置在表格1中的相应文本框中.

请帮助我.

谢谢,

Viswanathan.M




Now My Question is,if i use datagridview in a form 2, how can i place these datas in corresponding text boxes present in form 1 by using cell enter event.

Kindly help me.

Thanks,

Viswanathan.M

推荐答案

可能有两种方法可以完成此任务
>通过设置属性访问两个文本框
>将其公开

创建具有文本框的Next表单的对象.
Form2 f2 = new Form2();
现在在单元格输入事件中,您可以使用代码

there may be two methods to do this task
>access two text boxes by setting properties
>make them public

Create the object of Next form which have text boxes.
Form2 f2=new Form2();
now on cell enter event you can use the code

 f2.textbox1.text=dgvPhone.Rows[e.RowIndex].Cells["data1"].Value.ToString();
f2.textbox2.text=dgvPhone.Rows[e.RowIndex].Cells["data2"].Value.ToString();
f2.show();


这篇关于如何从datagridview单元更新表单1中存在的数据进入表单2中的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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