Listview width with or without vertical scrollbar

3 posts, 0 answers
  1. Brendan
    Brendan avatar
    52 posts
    Member since:
    Dec 2011

    Posted 07 Oct 2014 Link to this post

    I have a RadListView, with a ViewType of Listview, and VerticalScrollBar set to AutoHide.  I simply want to get the width of the control including the scrollbar if visible.

    I have tried ClientRectangle.Width - it did not take into account the scrollbar.width

    So I tried checking the visibility of the scrollbar, if visible then subtract the scrollbar width.  Even when the scrollbar is visible, it always comes back as Visible=False.

    Is this a bug or am I doing wrong something wrong? 
    Dim iScroll As Integer = 0
     
    'get scrollbar width if needed
    If Me.lvwLoadForms.VerticalScroll.Visible = True Then iScroll = SystemInformation.VerticalScrollBarWidth
     
    'resize items and group widths
    With Me.RadListView1
        .GroupItemSize = New Size(.Width - iScroll, .GroupItemSize.Height)
        .ItemSize = New Size(.Width - .GroupIndent - iScroll, .ItemSize.Height)
    End With

  2. Dess
    Admin
    Dess avatar
    1717 posts

    Posted 13 Oct 2014 Link to this post

    Hello Brendan,

    Thank you for writing.

    Please have a look at the following code snippet demonstrating how to calculate the RadListView's width taking into consideration the vertical scroll bar if it is visible:
    public Form1()
    {
        InitializeComponent();
     
        for (int i = 0; i < 5; i++)
        {
            this.radListView1.Items.Add("Item" + i);
            this.radListView2.Items.Add("Item" + i);
        }
        for (int i = 5; i < 10; i++)
        {
            this.radListView2.Items.Add("Item" + i);
        }
    }
     
    private void radButton1_Click(object sender, EventArgs e)
    {
        int l1 = this.radListView1.Width;
        if (this.radListView1.ListViewElement.ViewElement.VScrollBar.Visibility == ElementVisibility.Visible)
        {
            l1 -= this.radListView1.ListViewElement.ViewElement.VScrollBar.Size.Width;
        }
        int l2 = this.radListView2.Width;
     
        if (this.radListView2.ListViewElement.ViewElement.VScrollBar.Visibility == ElementVisibility.Visible)
        {
            l2 -= this.radListView2.ListViewElement.ViewElement.VScrollBar.Size.Width;
        }
     
        this.radLabel1.Text = l1.ToString();
        this.radLabel2.Text = l2.ToString();
    }

    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Desislava
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Brendan
    Brendan avatar
    52 posts
    Member since:
    Dec 2011

    Posted 16 Oct 2014 in reply to Dess Link to this post

    Thank you, that works great.  I didn't know about the ListViewElement, but I will add the Control spy to the project to see if I can find some of these things on my own :-)
Back to Top