Acces to listbox in Panelbar

4 posts, 0 answers
  1. Declan
    Declan  avatar
    47 posts
    Member since:
    May 2007

    Posted 08 May 2009 Link to this post

    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
  2. Mike
    Admin
    Mike avatar
    640 posts

    Posted 08 May 2009 Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Declan
    Declan  avatar
    47 posts
    Member since:
    May 2007

    Posted 08 May 2009 Link to this post

    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
  5. Mike
    Admin
    Mike avatar
    640 posts

    Posted 11 May 2009 Link to this post

    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.
Back to Top