473,654 Members | 3,066 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Better way to load user controls into panel in Windows app?

I lost my last post, but I'm looking for a better way to manage loading user
controls (that are essentially forms) in a Windows app.

In my current design, I have a ListBar in which the user selects an item. I
then call a sub to loop through and remove any user control that may exist
in the panel. But then I have a wordy select statement to load up the user
control selected.

Isn't there a better way?

Thanks,
Ron
Private Sub ulbNav_ItemSele cted(ByVal sender As System.Object, ByVal e As
Infragistics.Wi n.UltraWinListB ar.ItemEventArg s) Handles ulbNav.ItemSele cted

RemoveExitingUs erControls()

Select Case e.Item.Key

Case "keyTesting_Vie wCountryList"

If _uctTesting_Vie wCountryList Is Nothing Then

_uctTesting_Vie wCountryList = New uctTesting_View CountryList

_uctTesting_Vie wCountryList.Pa rent = splContainer.Pa nel2

End If

Case "keyTesting_SQL ReportViewer"

If _uctTesting_SQL ReportViewer Is Nothing Then

_uctTesting_SQL ReportViewer = New uctTesting_SQLR eportViewer

_uctTesting_SQL ReportViewer.Pa rent = splContainer.Pa nel2

End If

Case "keyTesting_Cal culateDrivingDi stance"

If _uctTesting_Cal culateDrivingDi stance Is Nothing Then

_uctTesting_Cal culateDrivingDi stance = New
uctTesting_Calc ulateDrivingDis tance

_uctTesting_Cal culateDrivingDi stance.Parent = splContainer.Pa nel2

End If

End Select

End Sub

Feb 22 '07 #1
3 1993
On Feb 22, 12:34 pm, "Ronald S. Cook" <r...@westinis. comwrote:
I lost my last post, but I'm looking for a better way to manage loading user
controls (that are essentially forms) in a Windows app.

In my current design, I have a ListBar in which the user selects an item. I
then call a sub to loop through and remove any user control that may exist
in the panel. But then I have a wordy select statement to load up the user
control selected.

Isn't there a better way?
In your RemoveExitingUs erControls() sub, you could just do a
myPanel.Control s.Clear to remove the existing User Controls on the
panel, then do the myPanel.Control s.Add() for the next user control.

To avoid the messy select statement, you could use a custom class to
house each item in the ListView and initialize them during the form
load.

I'm not familiar with the type of List Control you're using, but I'm
assuming it behaves a bit like a ListBox and you can add custom items
to it and that it will call the ToString of your custom class to
figure out what text to display.

Class would look like:

Public Class MyListItem
Public Name As String
Public Control As Control

Public Overrides Function ToString() As String
Return Name
End Function
End Class

Form Code would look like:
Public Class Form1

Dim viewCountryList As New MyListItem
Dim sqlReportViewer As New MyListItem
Dim CalculateDrivin gDistance As New MyListItem

Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
' Initialize ViewCountryList
_uctTesting_Vie wCountryList = New uctTesting_View CountryList
viewCountryList .Control = _uctTesting_Vie wCountryList
viewCountryList .Name = "Country List"

' Initialize SQLReportViewer
sqlReportViewer .Control = _uctTesting_SQL ReportViewer
_uctTesting_SQL ReportViewer = New uctTesting_SQLR eportViewer
sqlReportViewer .Name = "Report Viewer"

' Initialize CalculateDrivin gDistance
CalculateDrivin gDistance.Contr ol = New
uctTesting_Calc ulateDrivingDis tance
_uctTesting_Cal culateDrivingDi stance = New
uctTesting_Calc ulateDrivingDis tance
CalculateDrivin gDistance.Name = "Calculate Driving Distance"

' Add each MyListItem to the List control
ulbNav.Items.Ad d(viewCountryLi st)
ulbNav.Items.Ad d(sqlReportView er)
ulbNav.Items.Ad d(CalculateDriv ingDistance)

End Sub

Private Sub ulbNav_ItemSele cted(ByVal sender As System.Object,
ByVal e As
Infragistics.Wi n.UltraWinListB ar.ItemEventArg s) Handles
ulbNav.ItemSele cted

Dim selectedListIte m As MyListItem

RemoveExitingUs erControls()

' Convert the generic Object to the MyListItem type
selectedListIte m = CType(e.Item, MyListItem)

' Add the control
splContainer.Pa nel2.Controls.A dd(selectedList Item.Control)

End Sub

Private Sub RemoveExitingUs erControls()
splContainer.Pa nel2.Controls.C lear()
End Sub

End Class

Feb 22 '07 #2
Jayeldee,

Thanks for the response. But, when I run this I get:

Unable to cast object of type 'Infragistics.W in.UltraWinList Bar.Item' to
type 'FRC.COW.Feedya rd.MyListItem'.

... at run-time when it hits the line:

selectedListIte m = CType(e.Item, MyListItem)

Any thoughts?

Thanks,
Ron


"jayeldee" <ja******@gmail .comwrote in message
news:11******** **************@ p10g2000cwp.goo glegroups.com.. .
On Feb 22, 12:34 pm, "Ronald S. Cook" <r...@westinis. comwrote:
>I lost my last post, but I'm looking for a better way to manage loading
user
controls (that are essentially forms) in a Windows app.

In my current design, I have a ListBar in which the user selects an item.
I
then call a sub to loop through and remove any user control that may
exist
in the panel. But then I have a wordy select statement to load up the
user
control selected.

Isn't there a better way?

In your RemoveExitingUs erControls() sub, you could just do a
myPanel.Control s.Clear to remove the existing User Controls on the
panel, then do the myPanel.Control s.Add() for the next user control.

To avoid the messy select statement, you could use a custom class to
house each item in the ListView and initialize them during the form
load.

I'm not familiar with the type of List Control you're using, but I'm
assuming it behaves a bit like a ListBox and you can add custom items
to it and that it will call the ToString of your custom class to
figure out what text to display.

Class would look like:

Public Class MyListItem
Public Name As String
Public Control As Control

Public Overrides Function ToString() As String
Return Name
End Function
End Class

Form Code would look like:
Public Class Form1

Dim viewCountryList As New MyListItem
Dim sqlReportViewer As New MyListItem
Dim CalculateDrivin gDistance As New MyListItem

Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
' Initialize ViewCountryList
_uctTesting_Vie wCountryList = New uctTesting_View CountryList
viewCountryList .Control = _uctTesting_Vie wCountryList
viewCountryList .Name = "Country List"

' Initialize SQLReportViewer
sqlReportViewer .Control = _uctTesting_SQL ReportViewer
_uctTesting_SQL ReportViewer = New uctTesting_SQLR eportViewer
sqlReportViewer .Name = "Report Viewer"

' Initialize CalculateDrivin gDistance
CalculateDrivin gDistance.Contr ol = New
uctTesting_Calc ulateDrivingDis tance
_uctTesting_Cal culateDrivingDi stance = New
uctTesting_Calc ulateDrivingDis tance
CalculateDrivin gDistance.Name = "Calculate Driving Distance"

' Add each MyListItem to the List control
ulbNav.Items.Ad d(viewCountryLi st)
ulbNav.Items.Ad d(sqlReportView er)
ulbNav.Items.Ad d(CalculateDriv ingDistance)

End Sub

Private Sub ulbNav_ItemSele cted(ByVal sender As System.Object,
ByVal e As
Infragistics.Wi n.UltraWinListB ar.ItemEventArg s) Handles
ulbNav.ItemSele cted

Dim selectedListIte m As MyListItem

RemoveExitingUs erControls()

' Convert the generic Object to the MyListItem type
selectedListIte m = CType(e.Item, MyListItem)

' Add the control
splContainer.Pa nel2.Controls.A dd(selectedList Item.Control)

End Sub

Private Sub RemoveExitingUs erControls()
splContainer.Pa nel2.Controls.C lear()
End Sub

End Class

Mar 19 '07 #3
On Mar 19, 2:06 pm, "Ronald S. Cook" <r...@westinis. comwrote:
Jayeldee,

Thanks for the response. But, when I run this I get:

Unable to cast object of type 'Infragistics.W in.UltraWinList Bar.Item' to
type 'FRC.COW.Feedya rd.MyListItem'.

.. at run-time when it hits the line:

selectedListIte m = CType(e.Item, MyListItem)

Any thoughts?

Thanks,
Ron
Ron,

Sorry about that Exception. It's more than likely from me not being
familiar with the types of controls you're using.

Do the items in the ListBar have a Tag property where you could put
the custom object? It seems they don't use the same method that a
standard ListBox does when adding custom objects to it.

Mar 21 '07 #4

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

Similar topics

0
1895
by: Duncan Mole | last post by:
Hi, I have created a control which draws a title bar and provides a drop down menu for a Smart Device Application. It seemed to work fine until I came to add an event handler to act on Paint messages in the form which has drawn the control. Evidently, the control is consuming all of these messages. How can I pass them back/on? I have a reference to the owner form but calling Refresh() via this reference isn't helping. Help! Do I need to...
2
2236
by: David K. | last post by:
My question concerns C# Windows Forms user controls. I have created navigation user control. It gets the parent control's CurrencyManager to its bindable property. In the control, any change in the CurrencyManager position is displayed OK. But the problem is that the position of the parent CurrencyManager stays intact (doesn't change at all). In methods, a reference parameter solves such problem, but I don't know how to implement it with...
6
6652
by: Richard Brown | last post by:
Ok, I celebrate and rejoice in the Anchor property. So wonderful compared to the horrible 'resize' code I had to write in VB6, there is just no end to the wonders of VB.NET..... uh, ok..... BUT... I have a form with a lot of controls side by side, etc. The Anchor is really only useful to resize 1 control on each line (and move all the others). BUT, does anyone have any articles or other ways to do this? For example, I am working on...
7
2467
by: Mike Bulava | last post by:
I have created a base form that I plan to use throughout my application let call the form form1. I have Built the project then add another form that inherits from form1, I add a few panel controls each with a couple of controls in them I then rebuilt my project and my new panels and all controls they contained are gone... I've looked through the Auto generated code but don't see anything that looks wrong Any body have any idea why this...
0
1250
by: alwayssmiling | last post by:
Hi, In my application, In the main form tab control is there. For this im adding a tabpage which contains a user control, this usercontrol contains many windows controls and other userdefined controls. In this Usercontrol a panel is there, which is a parent control for all reamaining controls. In this panel, a splitter control is there, in this splitter control left side i have another panel. In order to resize the controls based on the...
6
4720
by: Ronald S. Cook | last post by:
We have a Windows app that has one main form (a shell, sort of). We then load user controls into a panel on the form depending on what the user has selected. Our current code to unload the existing user control and load the newly selected one is pretty bulky. Every time we add a new user control to the project, we have to add some code in the section where we are loading/unloading. Is there a more dynamic, more efficient way to...
2
13581
by: Ronald S. Cook | last post by:
I have a Windows app with a split container (SplitContainer1) that contains two panels (Panel1, Panel2). I would like to load a user control (utcMyTest) into Panel2 on form load. Can someone please tell me the line(s) of code to do that? Also, is there an easy/dynamic way to unload whichever user control is already in there? I'm assuming only one can be in there at a time, right?
3
1996
by: Ronald S. Cook | last post by:
I'm developing a Windows application that will have an ListBar like in Outlook. When the user clicks on a ListBar item, I would like to load the associated User Control. The below code works fine, but I'm looking for something more dynamic (since we'll have dozens if not hundreds of user listbar items/user controls). private void ulbListBar_ItemSelected(object sender, Infragistics.Win.UltraWinListBar.ItemEventArgs e) {...
0
2861
by: MasterOfTheDark | last post by:
This one's a hairy one to explain. What I've got is a class called "VistaGroupBox" that I put some nice-looking Vista-style gradients in the background and made to look like the ribbon categories you see in Office 2007. I got it working great, and created a few more controls, including a "VistaButton", which is primarily transparent when the cursor does not hover over it. However, when I added a standard Panel in the VistaGroupBox and put my...
0
8710
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...
0
8598
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7310
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
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
5627
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
4150
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
4299
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2721
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
2
1598
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.