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

Listview width with or without vertical scrollbar

2 Answers 1194 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Brendan
Top achievements
Rank 1
Brendan asked on 07 Oct 2014, 10:25 PM
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 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 13 Oct 2014, 06:20 AM
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.

 
0
Brendan
Top achievements
Rank 1
answered on 16 Oct 2014, 08:38 PM
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 :-)
Tags
ListView
Asked by
Brendan
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Brendan
Top achievements
Rank 1
Share this question
or