Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

C# Open form instances how to close.

$
0
0
I have a program that i am working on. The user presses some shortcut keys this they opens a form with a list of suppliers in a datagrid View. User clicks them and it passes back across to the original form. The problem with my code is the original form there is 3 instances of it open 3 copies of form.

Code For the shortcut keys to open the list
   if (e.KeyCode == Keys.B && e.Modifiers == Keys.Control)
            {
                OpenCloseForms OpenSupplierList = new OpenCloseForms();
                OpenSupplierList.OpenListSupplierForm();
                OpenSupplierList.CloseSupplierForm();
                
            }


Code for the datagrid view click that passes data to the form
   OpenCloseForms form2 = new OpenCloseForms();
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > 0 && e.ColumnIndex > 0)
            {
                
               form2.OpenSupplierForm();
               string supplierCode1 = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
               form2.SetSupplierCode(supplierCode1);
               
                
                //form2.CloseSupplierForm();
            }
            else MessageBox.Show("Value wrong");
        }

I have tried a few things including this.close(); on the instances of the form with no success. Anyone have any ideas on how i could correct this and point me in he right direction any help at all appropriated.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>