-1

我有一个父表单 QuotationDetails,其中有一个名为 ChooseCustomer 的按钮,当我单击它时,会打开一个名为 CustomerSearchForm 的子表单。现在有一个 Datagridview CustomerSearchForm 有两个按钮 OK 和 CANCEL。所以当我从 DGV 中选择一行时,单击确定,该行中的所有详细信息都使用选定的客户客户数据填充到 QuotationDetails(大约 20 个文本框)中。我已经编写了所有代码并且工作正常。但问题是我通过关闭父表单 QuotationDetails 来做到这一点并打开它的一个新实例。但要求是我需要显示父窗体并从子窗体更新文本框。

下面是从 ChildForm 加载客户详细信息的代码

public void btnLoadCustomerDetails_Click(object sender, EventArgs e)
        {
            QuotationManagement objQM = new QuotationManagement();
           string[] Details = new string[gvCustomerDetails.SelectedRows[0].Cells.Count];
            for (int i = 1; i < gvCustomerDetails.SelectedRows[0].Cells.Count; i++)
            {
                Details[i] = gvCustomerDetails.SelectedRows[0].Cells[i].Value.ToString();
            }
            objQM.txtCustomerdetails.Text = Details[3] + Environment.NewLine + Details[4] + "," + Details[5] + "," + Details[6] + "," + Details[7];
            objQM.txtcustContact.Text = Details[3];
            objQM.txtCustPhoneno.Text = Details[10];
            objQM.txtfaxNo.Text = Details[12];
            objQM.txtCustMobile.Text = Details[15];
            objQM.txtcustemail.Text = Details[14];
            objQM.txtCustWeb.Text = Details[16];
            objQM.txtcustsource.Text = Details[29];
            objQM.txtCustActivestatus.Text = Details[27];
            objQM.txtCustomerType.Text = Details[44];
            objQM.txtCustNomAccType.Text = "Customer Quotations";
            objQM.txtCustAccStatus.Text = Details[25];
            objQM.txtTerms.Text = Details[31];
            objQM.txtCurrency.Text = Details[33];
            objQM.txtcountryname.Text = Details[9];
            objQM.lblCustomermasterId.Text = Details[0];
            this.Close();
            objQM.tabQuotationManagement.SelectedIndex = 1;
            objQM.Show();            

        }

我已经搜索了一个解决方案,并得到了一个使用 Event 和一个 Delegate 来触发它的想法。

但我不确定如何在我的场景中实现相同的功能。

请指教。

谢谢你。

4

2 回答 2

0

Thanks for the help.Below is the code I have implemented using a constructor.

Code for CustomerSearch OK button

public void btnLoadCustomerDetails_Click(object sender, EventArgs e)
{
selectedRow = gvCustomerDetails.SelectedRows[0];
QuotationManagement objQM = new QuotationManagement(selectedRow);
objQM.tabQuotationManagement.SelectedIndex = 1;
objQM.Show();
this.Close();


}

Code for QuotationDetails form to load the CustomerDetails

public QuotationManagement(DataGridViewRow SelectedRow)
{
InitializeComponent();
CusRow = SelectedRow;
LoadSelectedCustomerDetails(CusRow);

}


private void LoadSelectedCustomerDetails(DataGridViewRow CusRow)
{
txtCustomerdetails.Text = CusRow.Cells[3].Value.ToString() + Environment.NewLine + CusRow.Cells[4].Value.ToString() + "," + CusRow.Cells[5].Value.ToString() + "," + CusRow.Cells[6].Value.ToString() + "," + CusRow.Cells[7].Value.ToString();
txtcustContact.Text = CusRow.Cells[3].Value.ToString();
txtCustPhoneno.Text = CusRow.Cells[10].Value.ToString();
txtfaxNo.Text = CusRow.Cells[12].Value.ToString();
txtCustMobile.Text = CusRow.Cells[15].Value.ToString();
txtcustemail.Text = CusRow.Cells[14].Value.ToString();
txtCustWeb.Text = CusRow.Cells[16].Value.ToString();
txtcustsource.Text = CusRow.Cells[29].Value.ToString();
txtCustActivestatus.Text = CusRow.Cells[27].Value.ToString();
txtCustomerType.Text = CusRow.Cells[44].Value.ToString();
txtCustNomAccType.Text = "Customer Quotations";
txtCustAccStatus.Text = CusRow.Cells[25].Value.ToString();
txtTerms.Text = CusRow.Cells[31].Value.ToString();
txtCurrency.Text = CusRow.Cells[33].Value.ToString();
txtcountryname.Text = CusRow.Cells[9].Value.ToString();
lblCustomermasterId.Text = CusRow.Cells[0].Value.ToString();     

}

Apart from loading the textboxes in Quotation form with the CustomerDetails. There are other additional textboxes where user can do manual entry.But when the user enters the data and then selects the customer data all the data in textboxes(manually entered) is lost. The reason is we are loading the form again.I can use Static to store the entered data.Apart from that is there any better way to do the same.

于 2013-02-14T05:18:39.477 回答
0

下面是返回选定 Gridview 行的子窗体的示例。

*** *主窗体

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {   //call the form
            MyChildForm cForm = new MyChildForm();
            if (cForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {   //get the selected row object
                DataGridViewRow dgvRow = cForm.selectedRow;
            }
        }
    }
}

*** *儿童表格

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class MyChildForm : Form
    {
        public DataGridViewRow selectedRow;

        public MyChildForm()
        {
            InitializeComponent();
        }

        private void MyChildForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            //Forms closing so lets get the results
            selectedRow = dataGridView1.SelectedRows[0];
        }



    }
}
于 2013-02-13T19:57:55.737 回答