Fixed height radListBox

6 posts, 0 answers
  1. FrancoP
    FrancoP avatar
    7 posts
    Member since:
    Sep 2009

    Posted 12 Nov 2009 Link to this post

    Good morning.
        I want to programmatically add a fixed height radListBox in the Form_Load. The height should be calculated accordingly to the number of items in the listbox. But the GetItemHeight method returns zero in the Form_Load. If I add a test button, and in the Click event perform the GetItemHeight, the result is 16, ok. Another problem is that I have to add 2 (magic number?) to the total height, otherwise the vertical scrollbar will appear. How can I solve these 2 problems?
     
    Thank you
  2. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 18 Nov 2009 Link to this post

    Hi FrancoP,

    Thank you for the questions.
     
    You can go around the first issue by calculating the height in the Shown event of your form. I am afraid that you will have to make do with the magic number for now. We have plans to improve the virtualization of RadListBox in a future release, which will cause some glitches in the layout to disappear.

    Please write again if you have other questions.
     

    Best wishes,
    Victor
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. FrancoP
    FrancoP avatar
    7 posts
    Member since:
    Sep 2009

    Posted 27 Nov 2009 Link to this post

    Thank you for your answer, but I can't use the shown event. I have to calculate the height of the item before the listbox be display. Is there a method to do so?
  5. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 30 Nov 2009 Link to this post

    Hello FrancoP,

    GetItemHeight() method always returns 16 in the Form load event handler when I am testing it. Are you sure your items are added to the list box? If they are, please post a support ticket and attach a sample application so that I can debug it and provide a direct answer; this could be a potential issue. I am looking forward to your reply.

    Kind regards,
    Victor
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. FrancoP
    FrancoP avatar
    7 posts
    Member since:
    Sep 2009

    Posted 02 Dec 2009 Link to this post

    Hello Victor,

    I tried with a code like this (VB):

     

    Imports Telerik.WinControls.UI

     

    Public Class Form1

      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim rlb As New RadListBox

     

        Dim rlbi As New RadListBoxItem("Item1")

        rlb.Items.Add(rlbi)

        Dim h As Integer = rlb.GetItemHeight(0)

     

        Controls.Add(rlb)

     

      End Sub

    End Class

     

    and the value of ‘h’ is 0. If I calculate h after the ‘Controls.Add(rlb)’ I get 16 as expected.

    Is there a method to get the item height before adding the radListBox to the controls of the form?

     

    Kind regards

  7. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 07 Dec 2009 Link to this post

    Hi FrancoP,

    You need to add the RadListBox object to the Controls collection before calling the GetItemHeight() method. Simply move your Controls.Add(rlb) call to just before the Dim h As Integer  = rlb.GetItemHeight(0) statement.
    Please write again if you need further assistance.

    Best wishes,
    Victor
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top
UI for WinForms is Visual Studio 2017 Ready