views:

1312

answers:

6

I was wondering... I have a WinForms System.Windows.Forms.ListView with a bunch of ListViewItems that I'm drawing using the View.List style. Each ListViewItem has a "SmallIcon" that I fetch from the ListView's SmallImageList.

My problem is that the icons are showing too close to the border on the left. I've tried to change the bounds and the ListViewItem's Position property to no avail.

Is there anyway to have some kind of offset to ListViewItems?

A: 

Try setting ListView control's Padding.

Anna Lear
Winforms controls don't have padding...
Eric J.
@Eric: Not true, check the Control.Padding property. However, this will pad the entire control rather than the items area within the control.
Jeff Yates
+1  A: 

Try adding white space to the left of your small images.

If you're using 16x16 images change to 24x16 for example by adding 8 white (or ListView Background color) pixels to the left.

najmeddine
simpel but effective! Good answer
PoweRoy
A: 

A screenshot would be nice for an example to see exactly what you're after.

Funny thing... the Windows Explorer uses the ListView to display files and folders. i usually run my view in Report or Detail mode. i just switched it to List view mode and see the exact problem that you're describing! Yikes. Might be a bug with the Win32 object and that particular view type!

A quick workaround might be to use a Report style for the ListView with a single column or perhaps implement something yourself. The FlowLayoutPanel in .Net would work very nicely as a starting point for a custom list view.

Paul Sasik
A: 

As you are using the View.List style, I suspect you'll either need to implement some custom drawing or consider padding your images. You could also look at overriding the ListView control and manipulating it's bounds by overriding SetBoundsCore or SetClientSizeCore (or similar).

However, if the ListView were set-up for View.Details view, this could be done using the ListViewItem.IndentCount property:

The IndentCount property can be used only when the View property of the containing ListView is set to Details, and the SmallImageList property of the ListView is set. Source:MSDN

Jeff Yates
IndentCount works in multiples of the SmallImageList width. So setting IndentCount to 1, indents the text by 16 pixels (if the SmallImageList is 16x16). I think that is more than @Superoli needs :)
Grammarian
A: 

The Win32 listview control doesn't have any setting to increase the space between the icon and the label (in any view, not just List). Setting ListViewItem.Position does nothing when the ListView is in List view.

A low-tech solution would be to simply prefix every ListViewItem's Text value with a single space. Slightly ugly, but oh so easy to do.

If you really want to have pixel level control, you will have to owner draw it. As always, if you are doing anything with a .NET ListView, ObjectListView makes owner drawing your items trivial.

Grammarian
A: 

If you are in ListView View LargeIcons then you can postion the text using item.position

Wayne Funderburk