473,396 Members | 1,995 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

ListView Question...

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
2 1772
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: andrewcw | last post by:
I have a simple winform with the following code. But although I can read back the info, the display fails to provide the text or the cell background color changes. private void ListViewBroke()...
1
by: J_Max | last post by:
Hello, This might be a really easy question, but... I am developing a simple Smart Device application that uses a listview. I have a function that adds a item to the listview - code is below. I...
7
by: Dave Y | last post by:
I am a newbie to C# and am having trouble trying to override a ListView property method. I have created a new class derived from the Forms.Listview and I cannot figure out the syntax to override...
3
by: MikeY | last post by:
Hopefully someone can help me on this. I am using C#, making Windows forms. I have created a listView with checkbox's. I have enabled the checkboxes under the properties, and all the data,...
1
by: Derck | last post by:
SORRY, for the crosspost, but I think I posted it in the wrong group! Hello all, I have a question.. I am tying to make a global listview class where other listviews in my application points...
12
by: J L | last post by:
When I fill a listview, I resize the columns to fit the data. I need to know if the data will fit vertically or if there will be a vertical scroll bar. I need to know this so I can allow for it on...
1
by: Chris | last post by:
Hi all, I posted the following in microsoft.public.dotnet.framework.windowsforms but it seems that group has little traffic. Hi all, I have a listview box which is populated from methods of...
12
by: garyusenet | last post by:
I have had no replies to my previous post so perhaps I didn't write it good enough. Please excuse new thread but i wanted to break from the last thread hopefully this thread will be better. ...
1
by: =?Utf-8?B?THluYkBtcy5jb20=?= | last post by:
I have a executable winforms application I would like to change. I use quite a number of listview controls in my main form. I dump about 15 columns of data into a couple of listviews. This data...
5
by: Mark Olbert | last post by:
How do I get the DataPager and ListView to play nice together when I use a custom datasource? In my webpage, I use linq to pull data from a SqlServer database and assign the resulting...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.