|
-
Oct 31st, 2007, 12:07 AM
#1
Thread Starter
Junior Member
[RESOLVED] Multiple forms
Thanks in advance for help!
I have a main form doing it's with a Listbox on it and information loaded from a DB. When a user clicks add it opens a second form (frmAddRecord) and the user fills the info to add a new record to the DB. What I can't figure out how to do is when they click add on the second form, it adds the info and then closes that form. How do I tell form1 to refresh the listbox? That's all I really need to figure out how to do. What even happens when the second one closes and the first one is primary again. I tried "Gotfocus", but that didn't do it.
Any ideas?
Thanks again
-
Oct 31st, 2007, 12:22 AM
#2
Re: Multiple forms
Your ListBox should be bound to the DataTable containing the data. If you pass the appropriate DataRow to the dialogue then when you update it the ListBox will automatically reflect the changes. The "Update Grid Row in Dialogue" link in my signature shows you how to do this with a DataGridView. It's basically the same with a ListBox.
-
Oct 31st, 2007, 12:28 AM
#3
Thread Starter
Junior Member
Re: Multiple forms
Well, to work on my programming skills, I didn't use the built in stuff for data, I actually hard coded a connection to the dataset and whatnot. So when there's a change, I have a loop counting through the records in the dataset and adding them to the listbox. So I need to find a way to fire off a custom sub that I've made that does that. How can I run that Sub when the user closes the second form?
-
Oct 31st, 2007, 12:45 AM
#4
Re: Multiple forms
To display the dialogue you call ShowDialog, which doesn't return until the dialogue is closed. If you want to do something when the dialogue closes you do it immediately following ShowDialog, e.g.
vb.net Code:
Using dialogue As New DialogueForm 'Create the dialogue form.
'Pass the required data to the dialogue.
dialogue.SomeProperty = myListBox.SelectedItem
'Display the dialogue.
If dialogue.ShowDialog() = Windows.Forms.DialogResult.OK Then
'The user pressed the OK button so get the new data back from the dialogue.
myListBox.Items(myListBox.SelectedIndex) = dialogue.SomeProperty
End If
End Using 'The dialogue gets destroyed implicitly here.
-
Oct 31st, 2007, 12:46 AM
#5
Thread Starter
Junior Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|