PC Review


Reply
Thread Tools Rate Thread

How to show long labels on ListView columns?

 
 
Arto Viitanen
Guest
Posts: n/a
 
      19th Dec 2007
We have a program that lets the user to compare several files. The files
are shown in ListView, with dataitems on lines and each file on separate
column. Names of the files are used as column headers. Here comes the
problem: since there are several files and dataitems are quite short
(a number or short text), the columns are not very wide. But the file
names are quite long and are of something like:

directory\subdirectory\averyveryverylongname.txt
directory\subdirectory\averyveryverylongothername.txt
directory\subdirectory\averyveryverylongthird.txt

and since the ListView shows the name starting from left, each column
seems to have same the name.

I tried to put the columns right aligned, but still the writing starts
from the left.

I guess the ideal case is to show the names like

dir...longname.txt
dir...thername.txt
dir...hirdname.txt

How can I make that?

If not, how to make tooltips with ListView columns (I found some code
with Google, but it assumed some Windows code I was not familiar with)?

--

Arto Viitanen
 
Reply With Quote
 
 
 
 
Claes Bergefall
Guest
Posts: n/a
 
      19th Dec 2007
For tooltips you should be able to use the ListView.ShowItemToolTips
property (combined with the ListViewItem.ToolTipText property)

If you want to shorten the display of your names you should be able to use
PathCompactPath or PathCompactPathEx. These are Win32 functions though. I'm
not sure if there's a .NET equivalent.

/claes

"Arto Viitanen" <(E-Mail Removed)> wrote in message
news:4768b688$0$3521$(E-Mail Removed)...
> We have a program that lets the user to compare several files. The files
> are shown in ListView, with dataitems on lines and each file on separate
> column. Names of the files are used as column headers. Here comes the
> problem: since there are several files and dataitems are quite short
> (a number or short text), the columns are not very wide. But the file
> names are quite long and are of something like:
>
> directory\subdirectory\averyveryverylongname.txt
> directory\subdirectory\averyveryverylongothername.txt
> directory\subdirectory\averyveryverylongthird.txt
>
> and since the ListView shows the name starting from left, each column
> seems to have same the name.
>
> I tried to put the columns right aligned, but still the writing starts
> from the left.
>
> I guess the ideal case is to show the names like
>
> dir...longname.txt
> dir...thername.txt
> dir...hirdname.txt
>
> How can I make that?
>
> If not, how to make tooltips with ListView columns (I found some code
> with Google, but it assumed some Windows code I was not familiar with)?
>
> --
>
> Arto Viitanen



 
Reply With Quote
 
Arto Viitanen
Guest
Posts: n/a
 
      20th Dec 2007
Claes Bergefall kirjoitti:
> For tooltips you should be able to use the ListView.ShowItemToolTips
> property (combined with the ListViewItem.ToolTipText property)


ListView column headers do not have ToolTipText property.

--
Arto Viitanen
 
Reply With Quote
 
Claes Bergefall
Guest
Posts: n/a
 
      20th Dec 2007

"Arto Viitanen" <(E-Mail Removed)> wrote in message
news:476a079a$0$27838$(E-Mail Removed)...
> Claes Bergefall kirjoitti:
>> For tooltips you should be able to use the ListView.ShowItemToolTips
>> property (combined with the ListViewItem.ToolTipText property)

>
> ListView column headers do not have ToolTipText property.
>


Ahh, right, missed that you talked about the headers. Then you'll have to
roll your own.

/claes


 
Reply With Quote
 
Arto Viitanen
Guest
Posts: n/a
 
      21st Dec 2007
Claes Bergefall wrote:
> "Arto Viitanen" <(E-Mail Removed)> wrote in message
> news:476a079a$0$27838$(E-Mail Removed)...
>> Claes Bergefall kirjoitti:
>>> For tooltips you should be able to use the ListView.ShowItemToolTips
>>> property (combined with the ListViewItem.ToolTipText property)

>> ListView column headers do not have ToolTipText property.
>>

>
> Ahh, right, missed that you talked about the headers. Then you'll have to
> roll your own.
>
> /claes
>
>


I tried:

[DllImport("shlwapi.dll", CharSet=CharSet.Auto)]
private static extern bool PathCompactPath(IntPtr hDC, [In, Out]
StringBuilder pszPath, int dx);

....
this.ColumnWidthChanged += new
ColumnWidthChangedEventHandler(mtListView_dstdiff_ColumnWidthChanged);

...

private void mtListView_dstdiff_ColumnWidthChanged(object sender,
ColumnWidthChangedEventArgs e)
{
if (e.ColumnIndex > 1)
using (Graphics graphics = Graphics.FromHwnd(this.Handle))
{
IntPtr hDc = graphics.GetHdc();
ColumnHeader header = this.Columns[e.ColumnIndex];
StringBuilder longName = new StringBuilder((string)header.Tag);
if (PathCompactPath(hDc, longName, header.Width))
{
header.Text = longName.ToString();
}
}
}

(Columns 0 and 1 do not contain the file names and I stored the original
name to column's Tag)

This works when the data is loaded, but when I try to change the column
size, the program gets exception that tells that ColumnInfo cannot be
change, in the line "header.Text = longName.ToString()".

Anyhow, the resulting string is not suitable, since as I told, the
filenames are something like

c:\first\second\third\theverylongfilename.txt

and PathToPathCcompact gives something like

....ird\thev...

whereas I'd like to get

c:\fir...ame.txt

Of cource, I could use the length of the string returned by
PathCompactPath and generate my own string, so could someone tell
how to change the column text dynamically?
--
Arto Viitanen
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
putting 2 long columns into multiple columns in excel page and sor bob_mhc Microsoft Excel Misc 1 25th Apr 2008 08:51 AM
How do I show/hide columns in ListView? =?Utf-8?B?TXJOb2JvZHk=?= Microsoft C# .NET 1 31st Oct 2006 07:29 PM
Combine multiple columns into two long columns, Repeating rows in first column anasab@gmail.com Microsoft Excel Misc 2 31st Jul 2006 10:45 PM
Combine multiple columns into two long columns, Repeating rows in first column anasab@gmail.com Microsoft Excel Misc 0 31st Jul 2006 06:07 PM
preview of labels in Word do not show outline of labels anymore =?Utf-8?B?bWFraW5nZmFjZXM=?= Microsoft Word Document Management 2 1st Dec 2004 02:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:12 AM.