Click here to Skip to main content
15,885,936 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everyone, i have an add person form in which have a button called "save and edit medical details". What i would like to do is when this button is clicked, the medical details form is opened up and the datagrid view in this form already has the correct person ID selected.
So if i added a new member called paul, the medical form datagrid view would already have paul selected for editing

thanks for your time!
Posted

1 solution

Just pass the id for the new member in the constructor of the edit form, and use it to select the right person in the datagrid.

Hope this helps.

In reply to your comment.
Say your second form was called EditForm, then you would create a constructor in this form that takes an int representing the selected members id. Then the form would use this information to select the right member, something like this (pseudocode):-

C#
public class EditForm
    {
        public EditForm(int memberID)
        {
            datagrid1.SelectedPerson = from person in datagrid1.datasource where person.id == memberID;
        }
    }


Then you would open this form when the button is clicked like this:-

C#
private void btnSaveAndEdit_Click(object sender, EventArgs e)
       {
           EditForm e = new EditForm(paulsID);
           e.showdialogue();
       }

This is obviously not real code, but should give you the idea of how to go about it.
 
Share this answer
 
v2
Comments
Member 7791974 17-Nov-11 9:44am    
i'm sorry, can you give me an example of this?
i am not able to understand clearly
Wayne Gaylard 17-Nov-11 10:03am    
Please see my updated answer.
Member 7791974 17-Nov-11 10:23am    
thank you so much!
i will work on this now and see how it goes!
Wayne Gaylard 17-Nov-11 10:38am    
Pleasure - hope you get it sorted.

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