Click here to Skip to main content
15,892,839 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
From my Controler class am opening a form1 having a DataGridView using ShowDialog() function

C#
frmOrderCodeResult objfrmOrderCodeResult = new frmOrderCodeResult();
DialogResult dr = new DialogResult();

dr = objfrmOrderCodeResult.ShowDialog(frmMain.SingletonReference);
if (dr == DialogResult.OK)
{                                
    OrderCodeModel objOrderCodeModel = new OrderCodeModel();
    Load(objOrderCodeModel);
}
else if (dr == DialogResult.Cancel)
{
     return;
}

form1 is having one OK button attached to DialogResult.OK and Cancel button attached to DialogResult.Cancel event and having a daga grid

Once code ran, it will open the dialog and waiting for my OK or Cancel response from dialog.
i have 2 requirements
1. if user select an item from grid and click on ok, it will continue to execute the below code in the controller as shown

C#
dr = objfrmOrderCodeResult.ShowDialog(frmMain.SingletonReference);
if (dr == DialogResult.OK)

. . .
. . .

2. user can double click the row, then also i need to continue to execute from the the same controller code

so i need to attach datagrid item double click event to DialogResult.OK and close my dialog.

Anybody faced similar requirement ? waiting for your valuable response with code block
Posted
Updated 23-May-12 1:46am
v2
Comments
VJ Reddy 23-May-12 7:46am    
Edit: pre tag for C# code added.

Hi ,
Check this
C#
dr = objfrmOrderCodeResult.ShowDialog(frmMain.SingletonReference);
          if (dr == DialogResult.OK)
          {
              dataGridView1.DoubleClick += new EventHandler(dataGridView1_DoubleClick);
          }
      

      void dataGridView1_DoubleClick(object sender, EventArgs e)
      {

      }

Best Regards
M.Mitwalli
 
Share this answer
 
register double click event on datagridview and on double clicking the row set the dialogresult to ok and close the form.

You will get the dialog result in dr. Rest will remain the same.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900