Z
Zach
I have a listview, and currently there is the situation where a user
can double click between two column headers, and the system will
automatically resize the column header to the width of the longest text
in that column. I want this calculation to take into account the width
of the header as well. Currently, if there are 0 items in the list,
this reduces my column header to a width of 0, which is obviously
wrong. I tried writing a function to call into the Win32 API, but for
whatever reason it's not working. The code I used was this:
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SendMessage(IntPtr hWnd,
[MarshalAs(UnmanagedType.U4)] int Msg, IntPtr wParam, IntPtr lParam);
private void AutosizeColumn(int ColumnIndex)
{
const int LVM_FIRST = 0x1000;
const int LVM_SETCOLUMNWIDTH = LVM_FIRST + 30;
IntPtr LVSCW_AUTOSIZE_USEHEADER = new IntPtr(-2);
IntPtr Index = new IntPtr(ColumnIndex);
Debug.Assert(listViewStatParse.Columns.Count > ColumnIndex,
"listViewStatParse.Columns.Count > ColumnIndex");
int Result = SendMessage(this.Handle, LVM_SETCOLUMNWIDTH, Index,
LVSCW_AUTOSIZE_USEHEADER);
}
But this causes all sorts of weird things to happen. Perhaps what I
really need is a way to manually get the font used by the column
header, and I can figure out the text metrics on my own, then manually
figure out the width of the text in the column header and the
individual items. Problem is I don't know how to get the font
information for the column headers. It doesn't seem to be related to
the font information in the individual list view items.
Any other suggestions appreciated.
Thanks
can double click between two column headers, and the system will
automatically resize the column header to the width of the longest text
in that column. I want this calculation to take into account the width
of the header as well. Currently, if there are 0 items in the list,
this reduces my column header to a width of 0, which is obviously
wrong. I tried writing a function to call into the Win32 API, but for
whatever reason it's not working. The code I used was this:
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SendMessage(IntPtr hWnd,
[MarshalAs(UnmanagedType.U4)] int Msg, IntPtr wParam, IntPtr lParam);
private void AutosizeColumn(int ColumnIndex)
{
const int LVM_FIRST = 0x1000;
const int LVM_SETCOLUMNWIDTH = LVM_FIRST + 30;
IntPtr LVSCW_AUTOSIZE_USEHEADER = new IntPtr(-2);
IntPtr Index = new IntPtr(ColumnIndex);
Debug.Assert(listViewStatParse.Columns.Count > ColumnIndex,
"listViewStatParse.Columns.Count > ColumnIndex");
int Result = SendMessage(this.Handle, LVM_SETCOLUMNWIDTH, Index,
LVSCW_AUTOSIZE_USEHEADER);
}
But this causes all sorts of weird things to happen. Perhaps what I
really need is a way to manually get the font used by the column
header, and I can figure out the text metrics on my own, then manually
figure out the width of the text in the column header and the
individual items. Problem is I don't know how to get the font
information for the column headers. It doesn't seem to be related to
the font information in the individual list view items.
Any other suggestions appreciated.
Thanks