Pass Value from Form2 ListView to Form1 DataGridView

喜欢而已 提交于 2019-12-25 01:46:46

问题


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.

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.

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.

Seeking for expert guidance/advices

Ahmed


回答1:


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

 public string SelectedCode { get; set; }

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;


来源:https://stackoverflow.com/questions/29096073/pass-value-from-form2-listview-to-form1-datagridview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!