Click here to Skip to main content
15,881,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
Please I have trying to code this scenario. I have designed a datagridview which loads data from a database (SQL server). Now I want to always click on a row in the datagridview to show the content in pop-up form. For instance I click on a row and an update form shows.
I do this easily in WPF but I have headaches when I try to do this in winform.
Any help will be appreciated. Thanks
Posted

1 solution

You will need a DataGrid click event (DoubleClick or maybe CellClick) and show your popup as a dialog > ShowDialog()

C#
private void DataGrid_DoubleClick(object sender, EventArgs e)
{
 PopUpForm popupform = new PopUpForm(Pass Parameter);
 popupform.ShowDialog(); 
 //Reload you DataGrid here
}


Parameter you are going to pass should be defined on your PopUpForm like

C#
public PopUpForm (type Parameter)
{
 InitializeComponent();
 parameter = Parameter; // assuming parameter is defined
}


Hope it helps
 
Share this answer
 
Comments
Boipelo 29-Aug-13 15:05pm    
In addition, if the expected parameter (by the PopUpForm) has been loaded to the DataGrid, you can get it...
ToWhateverType Parameter = Convert.ToWhateverType(DataGrid.SelectedRows[0].Cells["WhateverIsLoaded"].Value)
Gerald Maale 30-Aug-13 10:55am    
Here my sample code

tblData selected = gvData.SelectedRows as tblData;
           if (selected == null)
           {
                SLabel.Text = "Record not Selected. Select record!";
           }
           else
           {
               DataUpdate dataUpdate = new DataUpdate(selected);
               dataUpdate.ShowDialog();
           }
this works perfectly with wpf.
Can you get me a sample code to demonstrate between a datagridview and a form?
Thanks.
Boipelo 30-Aug-13 13:00pm    
I gave you a sample above, did you got stuck when trying it? I know, you didn't try it, you were looking in your WPF.
if (gvData.SelectedRows.Count == 0)
{
SLabel.Text = "Record not Selected. Select record!";
}
else
{
//Do something, check solution
}

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