Re: Scollable property in Listview class breaks column headers by Erik
Erik
Wed Sep 20 14:23:18 CDT 2006
Thought I might aswell share my solution if anyone else has run inte the
same problem...
Use the ShowScrollBar win32 API function and call it from an overridden
OnSizeChanged method in a subclassed ListView.
[DllImport("user32.dll")]
static extern bool ShowScrollBar(IntPtr hWnd, int wBar, bool bShow);
private const int SB_HORZ = 0;
private const int SB_VERT = 1;
protected override void OnSizeChanged(EventArgs e)
{
ShowScrollBar(this.Handle, SB_HORZ, false);
ShowScrollBar(this.Handle, SB_VERT, false);
base.OnSizeChanged (e);
}
This will hide the scrollbars.
I also added code to prevent columns to be resized more then the ListView
control's width.
"Erik Alsmyr" <erik.alsmyr@gmail.com> wrote in message
news:eeqrjq$d7d$1@black.telenor.se...
>I read that post and tried it but without success. Thanks for the
>suggestion though.
>
> Seems I have to meddle with the message loops and use "unsafe" code to
> work around this.
>
> "Claes Bergefall" <louplou@nospam.nospam> wrote in message
> news:%23op6U8A3GHA.2152@TK2MSFTNGP06.phx.gbl...
>> "Erik Alsmyr" <erik.alsmyr@gmail.com> wrote in message
>> news:eeo9pv$rlq$1@black.telenor.se...
>>> When setting the Scrollable property of a listview and resizeing it the
>>> headers will be painted wrongly. This defect is documented in MSDN as:
>>>
>>> In versions of the .NET Framework prior to version 2.0, the column
>>> headers were not painted correctly when setting this property to false
>>> and resizing the control to make it larger. To work around this issue,
>>> set this property to true in a ResizeBegin event handler and set it
>>> back to false in a ResizeEnd event handler.
>>>
>>> I honestly don't understand this workaround mentioned. The ResizeBegin
>>> and ResizeEnd event are available only on .NET framework 2.0 according
>>> to MSDN. Does this mean the provided workaround is valid only in
>>> versions of .NET framework where it is not needed?
>>
>> Yes, it sure looks that way. Even ignoring the version issue, the text is
>> rather strange. Why would you handle Form events to work around issues
>> with a control? The person that wrote that must have been drunk or
>> something :-)
>>
>>>
>>> Does anyone have a .NET framework 1.1 workaround around?
>>
>> Found a post that suggested that something like the following might work:
>> private void listView_Resize(object sender, System.EventArgs e)
>> {
>> this.listView.Scrollable = true;
>> this.listView.Scrollable = false;
>> }
>>
>> Haven't tried it myself though
>>
>> /claes
>>
>
>