-1

ChooseCustomer というボタンがある親フォーム QuotationDetails があり、それをクリックすると CustomerSearchForm という名前の子フォームが開きます。これで、2 つのボタン [OK] と [CANCEL] を持つ Datagridview CustomerSearchForm があります。DGV から行を選択すると、 [OK] をクリックすると、その行のすべての詳細が、選択した顧客の顧客データで QuotationDetails (約 20 個のテキストボックス) に入力されます。すべてのコードを記述し、正常に動作しています。それの新しいインスタンスを開きます。しかし、要件は、親フォームを表示し、子フォームからテキストボックスを更新する必要があることです。

以下は、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();            

        }

私は解決策を探し、イベントとデリゲートを使用してそれをトリガーするアイデアを得ました。

しかし、私のシナリオで同じものを実装する方法がわかりません。

お知らせ下さい。

ありがとうございました。

4

2 に答える 2

0

助けてくれてありがとう。以下は、コンストラクターを使用して実装したコードです。

CustomerSearch OK ボタンのコード

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();


}

CustomerDetails をロードする QuotationDetails フォームのコード

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();     

}

CustomerDetails を使用して見積もりフォームにテキストボックスをロードすることとは別に。ユーザーが手動で入力できるテキストボックスは他にもありますが、ユーザーがデータを入力してから顧客データを選択すると、テキストボックス (手動で入力) のすべてのデータが失われます。その理由は、フォームを再度ロードしているためです。静的を使用して、入力したデータを保存できます。それとは別に、同じことを行うためのより良い方法があります。

于 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 に答える