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
|