Results 1 to 3 of 3

Thread: Triggering a routine in the parent form

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    2

    Triggering a routine in the parent form

    Hi all! I've been having no luck at all the past few months triggering an event within my parent form, from my child form...

    Allow me to elaborate...

    I have a function that loads some dabase info into a list view:
    Code:
    public void photologload()
    		{
    			OleDbConnection Myconnection = null; 
    			OleDbDataReader dbReader = null; 
    
    			Myconnection = new OleDbConnection (@"Provider=Microsoft.Jet.OLEDB.4.0; User Id=; Password=; Data Source=ghostphotos.mdb"); 
    			
    			Myconnection.Open(); 
    
    			OleDbCommand cmd = Myconnection.CreateCommand(); 
    			cmd.CommandText = "SELECT * FROM photos"; 
    			dbReader = cmd.ExecuteReader(); 
    
    			int ida;
    		
    				
    			while(dbReader.Read()) 
    			{ 
    				ida = (int)dbReader.GetValue(0);
    				nameofphoto = (string)dbReader.GetValue(1); 
    				photodescription = (string)dbReader.GetValue(2);
    				pathtophoto = (string)dbReader.GetValue(3);
    				datetaken = (string)dbReader.GetValue(4);
    				photosummary = (string)dbReader.GetValue(5);
                    //populate the log box
    				ListViewItem lvItem = photoview.Items.Add(datetaken);
    				lvItem.Tag = ida;
    				lvItem.SubItems.Add(nameofphoto);
    				lvItem.SubItems.Add(photodescription);
    								
    			} 
    			
    			dbReader.Close(); 
    			Myconnection.Close(); 
    		}
    I then have a button on my form that allows me to add a new photo via a child form:

    Code:
    private void newphoto_Click(object sender, System.EventArgs e)
    		{
    					
    				photoadd newphoto = new photoadd();
    				newphoto.Show();
    		}
    What I want to do is, when I close the child form, I want the photoloadlog event to occur. I've tried passing variables, checking states of the child, etc, and nothign seems to get it to work correctly.

    Any insight into this one would be greatly appreciated!!!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Triggering a routine in the parent form

    Do you want to be able to access the parent form while this child form is visible? If not then you should be calling ShowDialog rather than Show. ShowDialog blocks until the form is dismissed, so when ShowDialog retruns you know that the form has been dismissed and you can perfrom whatever action is required.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    2

    Re: Triggering a routine in the parent form

    Sir I bow to you! Thank you!
    In all this time I have never even though of that!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width