Hello,
Situation:
I have a drop down list on a main form in my program. I have another form
for entering a new item that will reside in the drop down list of the main
form. When the Add item button is clicked on the second form, the second
form closes, but I also want the main form to rebind the data in the drop
down list.
I'm not sure how to tell the main form to rebind the data from the
form2_Closed event.
When I google this problem I get a ton of info on MDI, but that is not the
situation I'm looking for.
I've also looked into form1.FromHandle(form2) but I don't know how to get
the handle of a form, or even if this is the appropriate way of going about
this.
Thanks in advance,
- Paul 5 1715
I might need to rephrase this...
I would like to access functions I've created in a parent form from a child
form (not MDI parent/child, but form1 instantiates a new form2).
Thanks,
- Paul
"Paul Daly (MCP)" wrote: Hello,
Situation: I have a drop down list on a main form in my program. I have another form for entering a new item that will reside in the drop down list of the main form. When the Add item button is clicked on the second form, the second form closes, but I also want the main form to rebind the data in the drop down list.
I'm not sure how to tell the main form to rebind the data from the form2_Closed event.
When I google this problem I get a ton of info on MDI, but that is not the situation I'm looking for.
I've also looked into form1.FromHandle(form2) but I don't know how to get the handle of a form, or even if this is the appropriate way of going about this.
Thanks in advance,
- Paul
I found a way around this problem... On form1, I call the logic I want to
occur when form2 or 3 or 4 closes when form1_Activated occurs.
Still curious about how to do this though...
Thanks
"Paul Daly (MCP)" wrote: Hello,
Situation: I have a drop down list on a main form in my program. I have another form for entering a new item that will reside in the drop down list of the main form. When the Add item button is clicked on the second form, the second form closes, but I also want the main form to rebind the data in the drop down list.
I'm not sure how to tell the main form to rebind the data from the form2_Closed event.
When I google this problem I get a ton of info on MDI, but that is not the situation I'm looking for.
I've also looked into form1.FromHandle(form2) but I don't know how to get the handle of a form, or even if this is the appropriate way of going about this.
Thanks in advance,
- Paul
Greetings Paul,
Question: Is the Form2 shown as Modal? If so you can use the
DialogResult to check if the user closed the dialog in a workable way.
Just make suere that when using Modal, add Me.Hide() on the OnClose
event.
Regards,
Paulo
Hi Paul,
Simply, each form has a property called "Owner", from the main form and just
before showing the child form, set the child form "Owner" property to "this"
(C#) or "Me" (VB.NET).
From inside MainForm code, do this:
C#
----
ChildForm cf = new ChildForm();
cf.Owner = this;
VB.NET
-------
dim cf as new ChildForm()
cf.Owner = Me
After that, at any time you want to reach a method in main form inside
ChildForm, just call the Owner property of the child and cast its refrence to
MainForm and call the method like this:
((MainForm)this.Owner).MethodName();
or use Me and CType for VB.NET
The logic is calling the Owner property from inside child code, and you
original set its reference to MainForm from MainForm it self.
Good Luck, hope that work with you
---
Ahmed Ghozzy
"Paul Daly (MCP)" wrote: Hello,
Situation: I have a drop down list on a main form in my program. I have another form for entering a new item that will reside in the drop down list of the main form. When the Add item button is clicked on the second form, the second form closes, but I also want the main form to rebind the data in the drop down list.
I'm not sure how to tell the main form to rebind the data from the form2_Closed event.
When I google this problem I get a ton of info on MDI, but that is not the situation I'm looking for.
I've also looked into form1.FromHandle(form2) but I don't know how to get the handle of a form, or even if this is the appropriate way of going about this.
Thanks in advance,
- Paul
Thanks Ahmed... this worked great!
(FYI for others who come across this article: I also had to make the method
on form1 public before form2 would be able to access the function.)
"Ahmed Ghozzy" wrote: Hi Paul,
Simply, each form has a property called "Owner", from the main form and just before showing the child form, set the child form "Owner" property to "this" (C#) or "Me" (VB.NET).
From inside MainForm code, do this:
C# ---- ChildForm cf = new ChildForm(); cf.Owner = this;
VB.NET ------- dim cf as new ChildForm() cf.Owner = Me
After that, at any time you want to reach a method in main form inside ChildForm, just call the Owner property of the child and cast its refrence to MainForm and call the method like this:
((MainForm)this.Owner).MethodName();
or use Me and CType for VB.NET
The logic is calling the Owner property from inside child code, and you original set its reference to MainForm from MainForm it self.
Good Luck, hope that work with you
--- Ahmed Ghozzy
"Paul Daly (MCP)" wrote:
Hello,
Situation: I have a drop down list on a main form in my program. I have another form for entering a new item that will reside in the drop down list of the main form. When the Add item button is clicked on the second form, the second form closes, but I also want the main form to rebind the data in the drop down list.
I'm not sure how to tell the main form to rebind the data from the form2_Closed event.
When I google this problem I get a ton of info on MDI, but that is not the situation I'm looking for.
I've also looked into form1.FromHandle(form2) but I don't know how to get the handle of a form, or even if this is the appropriate way of going about this.
Thanks in advance,
- Paul This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Aung |
last post by:
I have two classes under the same namespace. something like this:
class1
~~~~~
namespace myProject
{
class myUI
{
public System.Windows.Forms.Label lblStatus;
|
by: Chuck Bowling |
last post by:
C# newbie warning...
It'll probably be easier to explain what i want in code:
-------
abstract class Base
{
...
}
|
by: Lizim |
last post by:
Does anybody know if it is possible to write software that works across
multiple monitors? and if so, is it possible to program one so it is private
to the user / administrator and the other...
|
by: John Granade |
last post by:
I'm looking for the best way to make a dataset available from multiple
Windows forms. The dataset is created from
an XML file. I have a main form (frmMain) that loads the dataset and reads
the...
|
by: Gene Hubert |
last post by:
I seem to be getting crazy results when I have multiple
System.Windows.Forms.Timer objects in the same form running at the
same time. When only one timer is running I get the expected
behavior. ...
|
by: Becker |
last post by:
I have a datatable that I use to display running processes. These running
processes are spawned as different threads. I use the readerwriterlock
class to ensure that when I write to the datatable,...
|
by: Brett Romero |
last post by:
If my UI app uses three DLLs and two of those DLLs reference something
named utilities.dll, does the UI app load utilities.dll twice or does
the compiler recognize what is going on and load...
|
by: Mario |
last post by:
Hi,
I am trying to create an application with multiple windows forms. The
problem that I have is that after creating the window forms, I do not
know how to open formN after closing Main form. ...
|
by: bbepristis |
last post by:
I have an application I wrote that requires MS SQL Server Express So I
want my installer to call and control the MS SQL SERVER installer how
do I do this I have seen it done before Im just not sure...
|
by: =?Utf-8?B?UXVhbiBOZ3V5ZW4=?= |
last post by:
I am trying to create a generics class with multiple constrains, as follows:
public class KeyHandler<Twhere T : TextBoxBase, ComboBox
When I try that, the compiler would complain:
The class...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |