Click here to Skip to main content
15,937,066 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends...

When the vertical scrollbar becomes visible, it changes the inside width of the listview, so the total column width + the width of the vertical scrollbar becomes wider than the listview. To assure the horizontal bar does not become visible, make the width of one of the columns slightly less than usual. Play around with the width until the horizontal bar doesn't appear

Please Fast Replay

Thanks
Posted

1 solution

Hi,

Here you have some hints about ListView.
ListView.Size - gives you total size of control (width and height)
ListView.ClientSize - gives you total available area for drawing (width and height)

So, you can calculate difference between total width and client width:
var diff = listView1.Size.Width - listView1.ClientSize.Width;

Normally diff value will be around 4 pixels because of border and etc. If vertical scrollbar appears then (on my computer) diff is around 21 pixels.

You can handle form's or listview's ClientSizeChanged events to adjust column's width when control area was changed.

Additionally there are some properties of ListView control not available in design mode but you can set them in your code:
ListView.AutoResizeColumn i ListView.AutoResizeColumns
which are used to set specific columns or all columns resize style.

Here you have some links:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.size%28v=vs.110%29.aspx[^]
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.clientsize%28v=vs.110%29.aspx[^]
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.sizechanged%28v=vs.110%29.aspx[^]
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.clientsizechanged%28v=vs.110%29.aspx[^]
http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.autoresizecolumn%28v=vs.110%29.aspx[^]
http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.autoresizecolumns%28v=vs.110%29.aspx[^]

I hope it help you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900