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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Feb 22, 12:34 pm, "Ronald S. Cook" <r...@westinis.com> wrote:
>> 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
>
|