从Form2的ListView控件到Form1的DataGridView pass值 [英] Pass Value from Form2 ListView to Form1 DataGridView

查看:153
本文介绍了从Form2的ListView控件到Form1的DataGridView pass值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#应用2种形式,Form1将主要含形式的DataGridView,列帐户code,帐户名,金额,叙事。在present用户可以输入帐户code手动和使用SQL查询帐户名填充了相应标题。

I've 2 forms in C# Application, Form1 is main form containing DataGridView, columns are AccountCode, AccountName, Amount, Narration. At present user can enter AccountCode manually and using Sql query AccountName is populated with relevant title.

现在我正在寻找一种方式来该用户将搜索包含的ListView持有账户codeS和帐户名窗体2帐户code,用户DoubleClick或preSS确定按钮返回选定的值到Active行后Form1中的DataGridView。活动行是主要关注的问题在这里,因为查找窗体2不仅将用于输入新的记录还要更新其他记录也需要从窗体2的ListView查找值。

Now I am looking for a way to that user will search AccountCode in Form2 containing ListView holding AccountCodes and AccountName, after user DoubleClick or press OK button return selected value to Active row in Form1 DataGridView. Active Row is the main concern here, because look up Form2 will not only be used to enter new record but also to update other records which also require look up values from Form2 ListView.

我知道如何使用委托窗体2 ListView控件的值传递到Form1文本框,但不知道如何将它传递给DataGridView中的活动行。

I know how to pass values between Form2 ListView to Form1 TextBoxes using delegates, but don't know how to pass it to DataGridView's Active Row.

寻求专家指导/建议

艾哈迈德

推荐答案

在窗体2,您可以创建公共财产和设定值,按照你的逻辑

in the Form2 you can create public property and set value to that according to your logic

 public string SelectedCode { get; set; }

和在Form1中您可以访问公共财产和设定值的DataGrid例如:

and in Form1 you can access that public property and set value to datagrid for example

        Form2 frm2 = new Form2();
        frm2.ShowDialog(this);
        dataGridView1.SelectedCells[0].Value = frm2.SelectedCode;

这篇关于从Form2的ListView控件到Form1的DataGridView pass值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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