This is a migrated thread and some comments may be shown as answers.

Acces to listbox in Panelbar

3 Answers 111 Views
Panelbar (obsolete as of Q2 2010)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Declan
Top achievements
Rank 2
Declan asked on 08 May 2009, 09:11 AM
I am using the following code to build a PanelBar from a database table. For each "FileType" I add a panel and place a ListBox in the panel. This works just fine.

            For Each itemFileTypes In collFileTypes 
                If itemFileTypes.IsInUse Then 
 
                    Dim newGroupElement As New RadPanelBarGroupElement 
 
                    newGroupElement.EnableHostControlMode = True 
                    newGroupElement.Caption = itemFileTypes.Descr 
                     
                    Dim lst As New RadListBox 
                    lst.Name = itemFileTypes.Descr 
                    lst.Dock = DockStyle.Fill 
                    lst.Text = itemFileTypes.Type 
 
                    newGroupElement.ContentPanel.Controls.Add(lst) 
 
                    radPanelBar.Items.Add(newGroupElement) 
                End If 
            Next 
 
            radPanelBar.Dock = DockStyle.Left 
            radPanelBar.ThemeName = "ControlDefault" 
 
            ' Set focus to Log panel 
            radPanelBar.Items("Log").Focus()  ' This throws exception

Later in my code I need to access the ListBox to assign its DataSource and load the appropriate data into each ListBox.

        ' For each panel find the listbox and assign its DataSource etc 
        ' add a listbox event handler for SelectedValueChanged. 
        Try 
            Dim pnl As RadPanelBarGroupElement 
 
            For Each pnl In radPanelBar.Items 
                Dim lst As RadListBox 
 
                'newGroupElement.ContentPanel.Controls.Add(lst) 
 
' This is where I come unstuck! 
 
                lst = pnl.Items(0)  or  pnl.ContentPanel.Controls(0) ???
 
                With lst 
                    .ValueMember = "id" 
                    .DisplayMember = "FileDescription" 
                    .DataSource = GetFileNamesByType(CType(lst.Text, Integer)) 
 
                    '.EmptyRows = True 
                    AddHandler lst.SelectedValueChanged, AddressOf ListBoxSelectedValueChanged 
                End With 
            Next 





See where I come unstuck above. What am I missing?

                'newGroupElement.ContentPanel.Controls.Add(lst) 

If I added a listbox to the controls collection of the ContentPanel of the GroupItemElement, why can I not access the ContentPanel of the GroupElement?

e.g.

lst = GroupElement.ContentPanel.Controls(0)

Declan

3 Answers, 1 is accepted

Sort by
0
Mike
Telerik team
answered on 08 May 2009, 05:09 PM
Hello Declan,

The proper way to access the listbox control would be:

pnl.ContentPanel.Controls(0)


However, there is a known issue, related to ListBox, when it is data-bound in PanelBar if the PanelBar is in OtlookNavPane mode. In this case, the panel bar adds the child ContentPanel controls to its child Controls collection only when the corresponding item (PanelBarGroupElement) is selected. Then, RadListBox would not behave correctly and will not create its items, despite that its datasource is assigned. The solution to this problem would be to assign BindingContext of the Form to the ListBox before setting the DataSource:

lst.BindingContext = Me.BindingContext
lst.DataSource = ...

Let me know if you need assistance any further.

Best wishes,
Mike
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Declan
Top achievements
Rank 2
answered on 08 May 2009, 05:42 PM
Hi Mike,

Yes, thanks. That works a treat.

One final question on this:  How can I switch panels in code? After adding panels it is the last added that remains selected. I want to select the first panel. 

radPanelBar.Items(0).Select    or something like this?

Regards,
Declan
0
Mike
Telerik team
answered on 11 May 2009, 11:08 AM
Hello Declan ,

There is a Selected property on RadPanelBarGroupElement, however, you should cast the item to the corresponding type:

(DirectCast(radPanelBar1.Items(0), RadPanelBarGroupElement)).Selected = True

Or
(DirectCast(radPanelBar1.Items("Log"), RadPanelBarGroupElement)).Selected = True


Regards,
Mike
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Panelbar (obsolete as of Q2 2010)
Asked by
Declan
Top achievements
Rank 2
Answers by
Mike
Telerik team
Declan
Top achievements
Rank 2
Share this question
or