C#- 两种形式之间的数据传输 [英] C#- Data transfer between two forms
本文介绍了C#- 两种形式之间的数据传输的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两种形式.第一个有一个文本框.第二个有一个 devexpress 数据网格.我想实现这一目标:首先单击一个按钮并打开 form2.如果我在 form2 中单击数据网格中的一行,则该值应显示在 form1 中的文本框中.(form1 已打开.)我是初学者.感谢您的帮助.
I have two forms. First one has one textbox.Second one has a devexpress data grid. I want to achieve that: first click a button and form2 opens. if I click a row in the data grid in form2, this value should be shown inside the textbox in form1.(form1 is already opened.) ı m a beginner. thanks for your help.
Form1 frm1 = new Form1();
frm1.textBox1.Text = gridView1.GetFocusedRowCellValue("ID").ToString();
frm1.Show();
当我这样做时,会打开一个新表单.我不想打开一个新表格.Form1 已经打开.我想向其文本框添加值.
when I do that, a new form opens. I dont want to open a new form. Form1 is already opened. I want to add values to its textbox.
推荐答案
最后,我解决了这个问题.
Finally, I solved the problem.
Application.OpenForms["form1"].Controls["textBox1"].Text =
gridView1.GetFocusedRowCellValue("ID").ToString();
感谢您的帮助.
这篇关于C#- 两种形式之间的数据传输的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文