473,779 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Usercontrol: is this possible?

I created a UserControl (basically containing a datagridview for
showing some data). I need this UserControl to be visible on 2 forms
at the same time.

Here's a stripped down version of some code:

Dim Myusercontrol as UserControlData Grid
Myusercontrol = New UserControlData Grid

Dim myForm1 as new Form1
myForm1.control s.add(Myusercon trol)
myForm1.show

Dim myForm2 as new Form2
myForm2.control s.add(Myusercon trol)
myForm2.show
What is happening is myForm2 gets the usercontrol, but myForm1 doesn't.
If i flip the code, then, the reverse is true.

How can I get BOTH myForm1 AND myForm2 to get the exact same
usercontrol?

Thanks for all your help!

John

Jan 11 '06 #1
4 1190

johnb41 wrote:
I created a UserControl (basically containing a datagridview for
showing some data). I need this UserControl to be visible on 2 forms
at the same time.

Here's a stripped down version of some code:

Dim Myusercontrol as UserControlData Grid
Myusercontrol = New UserControlData Grid

Dim myForm1 as new Form1
myForm1.control s.add(Myusercon trol)
myForm1.show

Dim myForm2 as new Form2
myForm2.control s.add(Myusercon trol)
myForm2.show
What is happening is myForm2 gets the usercontrol, but myForm1 doesn't.
If i flip the code, then, the reverse is true.

How can I get BOTH myForm1 AND myForm2 to get the exact same
usercontrol?


You can't. Controls only have one parent. A quick look at the docs
doesn't turn up an explicit statement of this, but it's true. By way of
poor evidence, consider the Control's Parent property, which is a
single value.

Now, to actually solve your problem: One way might be to make the
'backend' (data-side) parts of your control Shared (not 100% if you can
even do this), so that when you add one grid to form1, and another to
form2, they both have the same data source. This would limit you to
only ever having one such across the whole app though. There are
probably better ways.

--
Larry Lard
Replies to group please

Jan 11 '06 #2
Larry Lard wrote:
johnb41 wrote:
I created a UserControl (basically containing a datagridview for
showing some data). I need this UserControl to be visible on 2 forms
at the same time.

Here's a stripped down version of some code:

Dim Myusercontrol as UserControlData Grid
Myusercontrol = New UserControlData Grid

Dim myForm1 as new Form1
myForm1.control s.add(Myusercon trol)
myForm1.show

Dim myForm2 as new Form2
myForm2.control s.add(Myusercon trol)
myForm2.show
What is happening is myForm2 gets the usercontrol, but myForm1 doesn't.
If i flip the code, then, the reverse is true.

How can I get BOTH myForm1 AND myForm2 to get the exact same
usercontrol ?

You can't. Controls only have one parent. A quick look at the docs
doesn't turn up an explicit statement of this, but it's true. By way of
poor evidence, consider the Control's Parent property, which is a
single value.

Now, to actually solve your problem: One way might be to make the
'backend' (data-side) parts of your control Shared (not 100% if you can
even do this), so that when you add one grid to form1, and another to
form2, they both have the same data source. This would limit you to
only ever having one such across the whole app though. There are
probably better ways.


I was thinking about this... Could you remove the control from Form1,
and add the instance to Form2 when Form2 is activated and back when
Form1 is activated? I know it isn't clean, but it was just the idea I
had when I read this...

Chris
Jan 11 '06 #3
Too bad this isn't really possible. But i found a way that will work
ok for my needs (your post gave me the idea):

On form1, i click a button and form2 loads. The Usercontrol from form1
disappears and re-appears on form2. I guess I can deal with that.

Now, when i close form2, i change the parent of the usercontrol to be
back to Form1.

This will work. Thanks for your help Larry and Chris!

John

Jan 11 '06 #4
Bob
Have you tried
Dim Myusercontrol1 as UserControlData Grid
Myusercontrol1 = New UserControlData Grid
Dim Myusercontrol2 as UserControlData Grid
Myusercontrol2 = New UserControlData Grid

Dim myForm1 as new Form1
myForm1.control s.add(Myusercon trol1)
myForm1.show

Dim myForm2 as new Form2
myForm2.control s.add(Myusercon trol2)
myForm2.show

Would that do it for you?
HTH
Bob
"johnb41" <js********@gma il.com> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.com...
I created a UserControl (basically containing a datagridview for
showing some data). I need this UserControl to be visible on 2 forms
at the same time.

Here's a stripped down version of some code:

Dim Myusercontrol as UserControlData Grid
Myusercontrol = New UserControlData Grid

Dim myForm1 as new Form1
myForm1.control s.add(Myusercon trol)
myForm1.show

Dim myForm2 as new Form2
myForm2.control s.add(Myusercon trol)
myForm2.show
What is happening is myForm2 gets the usercontrol, but myForm1 doesn't.
If i flip the code, then, the reverse is true.

How can I get BOTH myForm1 AND myForm2 to get the exact same
usercontrol?

Thanks for all your help!

John

Jan 11 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3972
by: ZhangZQ | last post by:
Supposing I have a class "UserControl1 : System.Windows.Forms.UserControl" in an Assembly "UI.dll", now I create an Application project and want to use the "UserControl1" in another AppDomain, private void CreateUIInAnotherDomain() { UI.UserControl1 ui = (UI.Cls)domain.CreateInstanceFromAndUnwrap(@".\UI.dll", "UI.UserControl1"); this.Controls.Add(ui);
2
1815
by: Lokhan Wong | last post by:
My question is whether it's possible to change the properties of a panel, that resides on the webform containing the usercontrol, in the usercontrol itself. Like this: <form> <asp:panel visibility=false .... </asp panel> <user:control> //a function here turns the visibilty to true </user:control>
5
5060
by: Lau Lei Cheong | last post by:
Hello, I'm writing a usercontrol to be included in my project. The usercontrol have a few javascript function to do the client-side tasks. However, the controls on the usercontrol seems to change at execution(e,g: the TextBox with id & name"txtbox" in usercontrol "folder1" will have name "folder1:txtbox" and id "folder1_txtbox" during execution) Since I'll use the control in many place inside my project, it's not possible for me to...
12
2212
by: Joe | last post by:
Hello All: Do I have to use the LoadControl method of the Page to load a UserControl? I have a class which contains three methods (one public and two private). The class acts as a control server. It "serves" back the required control (either WebControl or UserControl) based on the contents of an xml file. The code in the webform places each control in a TableCell. My problem is that the control server works as far as returning the...
9
14459
by: Marcelo Cabrera | last post by:
Hi, I have a user control that in turn creates a bunch of webcontrols dynamically and handles the events these webcontrols raise. It used to work fine on ASP .Net 1.1 but when compiled on 2.0 it does not. The problem is that the webcontrols get created on the OnLoad event of the usercontrol and the event handlers are assigned at the same time. I have to click twice on the controls for the events to be raised, the first time nothing...
5
3402
by: EqDev | last post by:
I have a class that is a control derived from UserControl. I want to use serialization and deserialization with this calss but I get an exception "Cannot serialize member System.ComponentModel.Component.Site of type System.ComponentModel.ISite because it is an interface.". I am not interested in serializing any member from the base class only the properties in the derived class. How can I prevent the entire base class from being...
4
2386
by: Michael | last post by:
Hi I know it sounds grazy to create an ActiveX Usercontrol with VB.NET, where a native tool for this already exists, VB6. The existing ActiveX Control Containers should be able to load dynamically the exisitng ActiveX Controls and also the new one written with VB.NET. We want to make this switch to the new technology, because the IDE is much more better, the WSDL support is much more better, OO is included, and so on .....
1
3250
by: Giovanni | last post by:
Dear Friends/Gurus, I have exhausted myself and have yet no solution to the following: I have an ASP.NET 2.0 Survey type application. On a page, I have placed a GridView which is bound to an SQLDataSource. The GridView contains 3 columns: QuestionNumber, QuestionText, and a TemplateField. Each row in the GridView represents a question in a table (Ex.: "18. Satisfaction Level").
0
826
by: somequestion | last post by:
now ...there are 2 control A and B A is Form control and B is UserControl A : Form {} B: UserControl {} i'd like to make inherit both userControl Form
0
1029
by: Arthur Milfait | last post by:
hey there, i'd like to do some wild thing like this: imagine a simple page with a navigation menu and an iframe. clicking on links in the menu loads the according page in the iframe. the menu is a web-usercontrol of type "MenuList" that uses web-usercontrols of type "MenuItem" for each link. so far nothing special. but now i'd like each page that can be loaded to be of an interface/type "IMenuItem" that publishes a getter for the...
0
9632
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9471
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7478
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6723
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4036
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.