473,378 Members | 1,507 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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_ItemSelected(ByVal sender As System.Object, ByVal e As
Infragistics.Win.UltraWinListBar.ItemEventArgs) Handles ulbNav.ItemSelected

RemoveExitingUserControls()

Select Case e.Item.Key

Case "keyTesting_ViewCountryList"

If _uctTesting_ViewCountryList Is Nothing Then

_uctTesting_ViewCountryList = New uctTesting_ViewCountryList

_uctTesting_ViewCountryList.Parent = splContainer.Panel2

End If

Case "keyTesting_SQLReportViewer"

If _uctTesting_SQLReportViewer Is Nothing Then

_uctTesting_SQLReportViewer = New uctTesting_SQLReportViewer

_uctTesting_SQLReportViewer.Parent = splContainer.Panel2

End If

Case "keyTesting_CalculateDrivingDistance"

If _uctTesting_CalculateDrivingDistance Is Nothing Then

_uctTesting_CalculateDrivingDistance = New
uctTesting_CalculateDrivingDistance

_uctTesting_CalculateDrivingDistance.Parent = splContainer.Panel2

End If

End Select

End Sub

Feb 22 '07 #1
3 1973
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 RemoveExitingUserControls() sub, you could just do a
myPanel.Controls.Clear to remove the existing User Controls on the
panel, then do the myPanel.Controls.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 CalculateDrivingDistance As New MyListItem

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
' Initialize ViewCountryList
_uctTesting_ViewCountryList = New uctTesting_ViewCountryList
viewCountryList.Control = _uctTesting_ViewCountryList
viewCountryList.Name = "Country List"

' Initialize SQLReportViewer
sqlReportViewer.Control = _uctTesting_SQLReportViewer
_uctTesting_SQLReportViewer = New uctTesting_SQLReportViewer
sqlReportViewer.Name = "Report Viewer"

' Initialize CalculateDrivingDistance
CalculateDrivingDistance.Control = New
uctTesting_CalculateDrivingDistance
_uctTesting_CalculateDrivingDistance = New
uctTesting_CalculateDrivingDistance
CalculateDrivingDistance.Name = "Calculate Driving Distance"

' Add each MyListItem to the List control
ulbNav.Items.Add(viewCountryList)
ulbNav.Items.Add(sqlReportViewer)
ulbNav.Items.Add(CalculateDrivingDistance)

End Sub

Private Sub ulbNav_ItemSelected(ByVal sender As System.Object,
ByVal e As
Infragistics.Win.UltraWinListBar.ItemEventArgs) Handles
ulbNav.ItemSelected

Dim selectedListItem As MyListItem

RemoveExitingUserControls()

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

' Add the control
splContainer.Panel2.Controls.Add(selectedListItem. Control)

End Sub

Private Sub RemoveExitingUserControls()
splContainer.Panel2.Controls.Clear()
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.Win.UltraWinListBar.Item' to
type 'FRC.COW.Feedyard.MyListItem'.

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

selectedListItem = CType(e.Item, MyListItem)

Any thoughts?

Thanks,
Ron


"jayeldee" <ja******@gmail.comwrote in message
news:11**********************@p10g2000cwp.googlegr oups.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 RemoveExitingUserControls() sub, you could just do a
myPanel.Controls.Clear to remove the existing User Controls on the
panel, then do the myPanel.Controls.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 CalculateDrivingDistance As New MyListItem

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
' Initialize ViewCountryList
_uctTesting_ViewCountryList = New uctTesting_ViewCountryList
viewCountryList.Control = _uctTesting_ViewCountryList
viewCountryList.Name = "Country List"

' Initialize SQLReportViewer
sqlReportViewer.Control = _uctTesting_SQLReportViewer
_uctTesting_SQLReportViewer = New uctTesting_SQLReportViewer
sqlReportViewer.Name = "Report Viewer"

' Initialize CalculateDrivingDistance
CalculateDrivingDistance.Control = New
uctTesting_CalculateDrivingDistance
_uctTesting_CalculateDrivingDistance = New
uctTesting_CalculateDrivingDistance
CalculateDrivingDistance.Name = "Calculate Driving Distance"

' Add each MyListItem to the List control
ulbNav.Items.Add(viewCountryList)
ulbNav.Items.Add(sqlReportViewer)
ulbNav.Items.Add(CalculateDrivingDistance)

End Sub

Private Sub ulbNav_ItemSelected(ByVal sender As System.Object,
ByVal e As
Infragistics.Win.UltraWinListBar.ItemEventArgs) Handles
ulbNav.ItemSelected

Dim selectedListItem As MyListItem

RemoveExitingUserControls()

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

' Add the control
splContainer.Panel2.Controls.Add(selectedListItem. Control)

End Sub

Private Sub RemoveExitingUserControls()
splContainer.Panel2.Controls.Clear()
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.Win.UltraWinListBar.Item' to
type 'FRC.COW.Feedyard.MyListItem'.

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

selectedListItem = 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
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...
2
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...
6
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......
7
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...
0
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...
6
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...
2
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...
3
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...
0
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
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...
0
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 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.