我想知道如何在c#中調用事件。實際上,我有一個datagridview雙擊事件,它在datagridview中填充f2的文本框和選定行的值,並在這些值的分配文本框中顯示form2。現在我想通過點擊一個按鈕來做到這一點,說當點擊該按鈕時,調用我的datagridview雙擊事件,下面是我的雙擊事件ty。如何通過單擊按鈕來調用datagridview事件?
private void kryptonDataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
try
{
frmUpdate f2 = new frmUpdate();
f2.txtboxClearingAgent.Text = kryptonDataGridView1.SelectedRows[0].Cells["Clearing Agent Name"].Value.ToString();
f2.textboxClientCode.Text = kryptonDataGridView1.SelectedRows[0].Cells["Client Code"].Value.ToString();
f2.txtboxClientName.Text = kryptonDataGridView1.SelectedRows[0].Cells["Client Name"].Value.ToString();
f2.txtboxPostalAddress.Text = kryptonDataGridView1.SelectedRows[0].Cells["Postal Address"].Value.ToString();
f2.txtboxTelephone.Text = kryptonDataGridView1.SelectedRows[0].Cells["Telephone"].Value.ToString();
f2.txtboxFax.Text = kryptonDataGridView1.SelectedRows[0].Cells["Fax"].Value.ToString();
f2.txtboxEmailAddress1.Text = kryptonDataGridView1.SelectedRows[0].Cells["E-mail Address 1"].Value.ToString();
f2.txtboxEmailAddress2.Text = kryptonDataGridView1.SelectedRows[0].Cells["E-mail Address 2"].Value.ToString();
f2.txtboxEmailAddress3.Text = kryptonDataGridView1.SelectedRows[0].Cells["E-mail Address 3"].Value.ToString();
f2.txtboxWebsite.Text = kryptonDataGridView1.SelectedRows[0].Cells["Website"].Value.ToString();
f2.txtboxChargeRate.Text = kryptonDataGridView1.SelectedRows[0].Cells["Charge Rate"].Value.ToString();
f2.txtboxTotalDepo.Text = kryptonDataGridView1.SelectedRows[0].Cells["Total Deposit"].Value.ToString();
f2.txtboxAccountBal.Text = kryptonDataGridView1.SelectedRows[0].Cells["Account Balance"].Value.ToString();
f2.Show();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
private void kryptonbtnEdit_Click(object sender, EventArgs e)
{
//using (frmUpdate frmUpdate = new frmUpdate())
//{
// DialogResult result = frmUpdate.ShowDialog();
//}
}
ty我會試試看並給予反饋 – RichieCr7
ty它的工作,現在我知道如何明確地調用函數 – RichieCr7
看到我的更新... @galaxybomb – dotctor