Can somebody tell me how to get the header height of a ListView.
Here's how to get the listview header height using Win32 Interop calls.
[Serializable, StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
const long LVM_FIRST = 0x1000;
const long LVM_GETHEADER = (LVM_FIRST + 31);
[DllImport("user32.dll", EntryPoint="SendMessage")]
private static extern IntPtr SendMessage(IntPtr hwnd, long wMsg, long wParam, long lParam);
[DllImport("user32.dll")]
private static extern bool GetWindowRect(HandleRef hwnd, out RECT lpRect);
RECT rc = new RECT();
IntPtr hwnd = SendMessage(ListView1.Handle, LVM_GETHEADER, 0, 0);
if (hwnd != null)
{
if (GetWindowRect(new HandleRef(null, hwnd), out rc))
{
int headerHeight = rc.Bottom - rc.Top;
}
}
This might be a little bit hacky but you can do:
listView.Items[0].Bounds.Top
This will only work if there is only one item in the list. So you might want to temporarily add one when you first create the list and keep the height value.
Else, you can always use:
listView.TopItem.Bounds.Top
To make the test at any moment, but you still need at least one item in the list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With