Windows Develop Bookmark and Share   
 index > Windows Forms General > Adding LVS_NOCOLUMNHEADER support to ListView descendent
 

Adding LVS_NOCOLUMNHEADER support to ListView descendent

Hi all,
I'm creating my own ListView, which inherits 99% of it's functionality from built in ListView. One thing which standard Win32 API Listview support is the ability to hide the Headers in View.Details mode, but the .NET version does not appear to support this. I have tried the following in an attempt to add this functionality to MyListView, but it is not working...

I thought that adding LVS_NOCOLUMNHEADER to the CreateParams style would help, but it does not.
Can someone tell me where I'm going wrong.

private const int LVS_NOCOLUMNHEADER = 0x4000;

protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;

if ( !fShowColumnHeaders )
{
// Hide the Column Headers
cp.Style |= LVS_NOCOLUMNHEADER;
}

return cp;
}
}

private bool fShowColumnHeaders;
// Declares the property.
[
Description("Show or hide the column headers")
]
public bool ShowColumnHeaders
{
// Sets the method for retrieving the value of your property.
get
{
return fShowColumnHeaders;
}
// Sets the method for setting the value of your property.
set
{
if ( fShowColumnHeaders != value )
{
fShowColumnHeaders = value;
RecreateHandle();
}
}
}


Thanks.
soulmate75  Thursday, April 09, 2009 9:09 AM
It worked fine when I tried your code, like it should. Both at design time and runtime. The code I tested:

using System;
using System.Windows.Forms;

public class MyListView : ListView {
private const int LVS_NOCOLUMNHEADER = 0x4000;
private bool fShowColumnHeaders;

public MyListView() {
this.View = View.Details;
}

protected override CreateParams CreateParams {
get {
CreateParams cp = base.CreateParams;
if (!fShowColumnHeaders) cp.Style |= LVS_NOCOLUMNHEADER;
return cp;
}
}
public bool ShowColumnHeaders {
get { return fShowColumnHeaders; }
set {
if (fShowColumnHeaders != value) {
fShowColumnHeaders = value;
RecreateHandle();
}
}
}
}
Hans Passant.
  • Marked As Answer bysoulmate75 Friday, April 10, 2009 6:33 PM
  •  
nobugz  Friday, April 10, 2009 1:37 AM
It worked fine when I tried your code, like it should. Both at design time and runtime. The code I tested:

using System;
using System.Windows.Forms;

public class MyListView : ListView {
private const int LVS_NOCOLUMNHEADER = 0x4000;
private bool fShowColumnHeaders;

public MyListView() {
this.View = View.Details;
}

protected override CreateParams CreateParams {
get {
CreateParams cp = base.CreateParams;
if (!fShowColumnHeaders) cp.Style |= LVS_NOCOLUMNHEADER;
return cp;
}
}
public bool ShowColumnHeaders {
get { return fShowColumnHeaders; }
set {
if (fShowColumnHeaders != value) {
fShowColumnHeaders = value;
RecreateHandle();
}
}
}
}
Hans Passant.
  • Marked As Answer bysoulmate75 Friday, April 10, 2009 6:33 PM
  •  
nobugz  Friday, April 10, 2009 1:37 AM
Very Odd. I was writing my version of ListView using notepd and compiling it with Mono on Win2000 and .NET 2.0 and it just wouldn't behave itself. But I just tried it on WinXP and my original does indeed work. Apologies for the waste of bandwidth. I'll have to find out why it does not work on Win2k with either Microsoft or Mono's environemnt.

Thanks for your tests nobugz.

PS. Why doesn't Microsoft support LVS_NOCOLUMNHEADER by default? How hard would it have been to add that?
soulmate75  Friday, April 10, 2009 6:32 PM

You can use google to search for other answers

Custom Search

More Threads

• Rich Text Box Questions
• Treeview: How to link node image (+/-) with node text to expand/collapse.
• Total Physical Memory mismatch
• Row and Column Selection in DataGridView
• Need help with BGWorker.
• How do I pass custom dataset from the web service to a windows application?
• list all available Servers
• simple question -Round Robin picturebox fill
• Multithreaded Drawing in Windows Forms + Managed DirectX
• Application.DoEvents and repeating events