Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one form Item Group..which have one button and one textbox when i click on button grid was open and when i double click on grid cell the cell value retrive on form textbox..

My problem is that when i fetch the grid data on form textbox the new form was open and old form is also open.. i want only new form opened...and close old form please help me
Posted
Comments
ravikiran from Hyderabad 10-Dec-13 5:25am    
Are you using Javascript code
kavita painter 10-Dec-13 5:26am    
No only C#...i develop desktop application
BillWoodruff 10-Dec-13 5:53am    
Please describe clearly what your Main Form is, what other Forms the Main Form creates an instance of and opens, and which Controls are on the Main Form, and which Controls are on other Forms.

Show the code where your Main Form creates other Forms.

We're not psychics.
agent_kruger 14-Dec-13 7:33am    
first of all are you using win. form or what?

The new form was opened because you used code along the lines of:

C#
ItemGroupForm igf = new ItemGroupForm();
...
igf.Show();

Which will always create a new instance.
Since you open the Grid form from the textbox form, why not pass the data back to the existing textbox form instead of creating a new one? It's not that complex, and it means your code is more OOP oriented and easier to maintain. Have a look at this: Transferring information between two forms, Part 2: Child to Parent[^]
And think of the Grid form as the Child, and the TextBox form as the Parent (Since it opened the Grid form in the first place).
 
Share this answer
 
this.hide() method


or


use constructor

when you come from form1 on form 2 take some integer value in constructor then write code form object.hide()
 
Share this answer
 
i hope, this code helps you
C#
REGISTRATION reg = new REGISTRATION();
           bool onsiteopen = false;
           foreach (Form S in Application.OpenForms)
           {
               if (S is REGISTRATION)
               {
                   onsiteopen = true;
               }

           }
           if (onsiteopen == true)
           {
               MessageBox.Show("this form is already open.");
               reg.Activate();
           }
           else
           {
               reg.MdiParent = this;
               reg.Show();
           }
 
Share this answer
 
v2
Comments
kavita painter 14-Dec-13 5:00am    
using this code i cant retrive the data...it show old form but not retrive data in it
Simple do this on datagrid cell double click
C#
Textbox1.Text = dataGridView1[0, e.RowIndex].Value.ToString();



see this
C#
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            Textbox1.Text = dataGridView1[0, e.RowIndex].Value.ToString();
           
        }


0 is my ID Column so ill get id on text box
 
Share this answer
 
v3
Comments
kavita painter 14-Dec-13 5:12am    
i get the value in textbox but not on existing form
jackspero18 21-Dec-13 4:47am    
then..??
Anyone can give me proper code??? stil i cant found solution...
 
Share this answer
 
Comments
jackspero18 14-Dec-13 4:42am    
when u double click on grid u want grid data on same form textbox or new form...???
kavita painter 14-Dec-13 4:45am    
on same form...
jackspero18 14-Dec-13 4:54am    
Check Updated Code.. now
Karthik_Mahalingam 14-Dec-13 4:48am    
Please use "Have a Question or Comment?" button to post comments or queries... Dont use Solution for asking queries....
kavita painter 14-Dec-13 5:02am    
ok....

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