如何将数据传递回父表单 [英] How to Pass data back to the Parent form

查看:82
本文介绍了如何将数据传递回父表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



i正在使用Windows应用程序。



当用户双击文本框我正在使用datagridview显示另一个表单。



当用户选择行时。选定的行数据已发送到父表单。



我能够发送值。但是这些值没有显示在文本框上。



i尝试使用像刷新这样的选项,更新表单但仍然无效。



请帮助我。



谢谢,

Hi Everyone,

i am working on windows application.

when user double click on the text box i am displaying the another form with datagridview.

when user select on the row. the selected row data has been send to the parent form.

i am able to send the values. but the values are not displaying on the textbox.

i have tried with the option like refresh, update the form but still it is not working.

kindly help me anyone.

thanks,

推荐答案

使用此模式:



Use this pattern:

class ParentForm : Form
{
    private ShowChildForm()
    {
        ChildForm child = new ChildForm();
        child.ShowDialog();
        int interestingValue = child.InterestingValue;
        child.Dispose();
    }
}

class ChildForm : Form
{
    public int InterestingValue { get; private set }
}

不接触来自儿童的父表单侧。孩子不应该对其父母有任何了解。只是实例化,做它应该做的事情(比如设置它的 InterestingValue )并且平静地死去。



同时,父母有了解它的孩子。毕竟,创建孩子的是 ParentForm 。因此,父母不需要知道它从孩子那里要求的价值就不会受到太大的伤害。

No touching the parent form from child side. Child should not need to know anything about its parent. Just get instantiated, do what it is supposed to do (like setting its InterestingValue) and die in peace.

Meanwhile, the parent has to know about its child. It's the ParentForm that created the child, after all. So the parent is not harmed too much with the need to know what value it requests from its child.


你好,

正如你提到的那样

我可以发送值。但值不会显示在文本框中。

我们可以通过查看代码来更有效地帮助您。

可能这个建议会帮助你:

创建datagridview cellcontentclick事件并在文本框中捕获你想要的值,然后用行和单元格将值赋给textbox datagridview的id。



Hello,
As you mentioned
"i am able to send the values. but the values are not displaying on the textbox."
we can help you out more effectively by seeing your code.
May be this suggestion will help you out:
Create datagridview cellcontentclick event and catch the row whose value you want in your textbox then assign the value to textbox with row and cell id of datagridview.

if(e.RowIndex>=0)
{
DataGridViewRow r = this.datagridviewid.Rows[e.RowIndex];
textboxid.text = r.Cells[2].Value.ToString();
}





如需更多访问以下链接:

http://www.c-sharpcorner.com/Blogs/15388/ display-selected-row-from-datagridview-to-textboxes-in-windo.aspx [ ^ ]


这篇关于如何将数据传递回父表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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