By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,838 Members | 1,623 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,838 IT Pros & Developers. It's quick & easy.

ListView Question...

P: n/a
I have a listview control containing a number of columns.
When I populate the listview columns with data I want to size each column
according to the following rules:

1. If the width of the data is greater than the width of the column header's
title then size the column to be the width of the data value.

2. If the width of the column header's title is greater than the width of
the data in the column then size the column to be the width of the column
header's title.

I can use the ColumnHeader.AutoResize method to size on either width of data
value or column header title, BUT, I cannot seem to be able to determine
which is the wider of the two to avoid displaying the ellipse (...). I was
trying to look for a way of detecting the ellipse (...) in the column
header's title but to no avail.

Does anyone out there know a way to do this?
Any assistance would be very much appreciated.
Many thanks.
Apr 22 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Steve,

comparing the length of the strings won't do obviously because the size of
the text on the screen and number of latters are not related e.g. 'WW' will
be wider than 'iii'.

I can see only 2 solutions:
1. Is to measure the displayed suze of the column header and content using
Graphics.MeasureString or TextRenderer.MeasureText
or

2. Depending on your expectations for the widest string you resize according
it and hope for the best. For exaple. The column header says ID and the
column value is a number at up to 4 digits long. It could be that all
columns have 1 digit number, but if you expect tha most of the times the ID
are going to be 4 digits it make sense to resize based on the column content
rather than the header.

I personally would preffer the 2 solution.
--
HTH
Stoitcho Goutsev (100)

"Steve Randall" <St**********@discussions.microsoft.com> wrote in message
news:6D**********************************@microsof t.com...
I have a listview control containing a number of columns.
When I populate the listview columns with data I want to size each column
according to the following rules:

1. If the width of the data is greater than the width of the column
header's
title then size the column to be the width of the data value.

2. If the width of the column header's title is greater than the width of
the data in the column then size the column to be the width of the column
header's title.

I can use the ColumnHeader.AutoResize method to size on either width of
data
value or column header title, BUT, I cannot seem to be able to determine
which is the wider of the two to avoid displaying the ellipse (...). I was
trying to look for a way of detecting the ellipse (...) in the column
header's title but to no avail.

Does anyone out there know a way to do this?
Any assistance would be very much appreciated.
Many thanks.

Apr 24 '06 #2

P: n/a
foreach (ColumnHeader ch in this.listView1.Columns)
{
ch.Width = -2;
}

Jason Newell

Steve Randall wrote:
I have a listview control containing a number of columns.
When I populate the listview columns with data I want to size each column
according to the following rules:

1. If the width of the data is greater than the width of the column header's
title then size the column to be the width of the data value.

2. If the width of the column header's title is greater than the width of
the data in the column then size the column to be the width of the column
header's title.

I can use the ColumnHeader.AutoResize method to size on either width of data
value or column header title, BUT, I cannot seem to be able to determine
which is the wider of the two to avoid displaying the ellipse (...). I was
trying to look for a way of detecting the ellipse (...) in the column
header's title but to no avail.

Does anyone out there know a way to do this?
Any assistance would be very much appreciated.
Many thanks.

Apr 24 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.