Hiding a ColumnHeader...

  • Thread starter Thread starter Alan Seunarayan
  • Start date Start date
A

Alan Seunarayan

Hello,
I have a number of ColumnHeaders that are 'hidden' (width
set to zero). However, it is still possible to size
them. The reason why they are hidden is to give the
illusion that they do not exist. Is there a way to stop
the user from being able to resize column headers that I
have set their width to zero?

Many thanks,

Alan
 
The only way to make the cols disappear completely is to make the
underlying data columns invisible. If I'm not mistaken, there's a
"visible" property on a DAtaCOlumn object.
Set this to false and your problem is solved.
 
Sorry,
I am actually using a ListView control.

Alan
[2 quoted lines suppressed] make the
[1 quoted line suppressed] there's a
[14 quoted lines suppressed] (width
[12 quoted lines suppressed]

Hmm. IN that case I don't think there's a way
 
Well there is a way and it is quite simple.

The columns are stored in the ListView.Columns collection, so you can remove
and add columns as you like.
Only those in the collection will be shown.

E.g.
System.Windows.Forms.ColumnHeader headerToShowHide = new
System.Windows.Forms.ColumnHeader();

private void ToggleColumn()
{
if (this.myListView.Columns.Contains(headerToShowHide))
{
this.myListView.Columns.Remove(headerToShowHide);
headerToShowHide.Text = "Now I am hidden";
}
else
{
headerToShowHide.Text = "See me now?";
this.myListView.Columns.Insert(1, headerToShowHide);
}
}

Just remove it when you want to hide it.
Insert it at the desired position and you see it again.

Eric-Paul Jansen
Inforay International B.V. (http://www.inforay.com)
The Netherlands

Roy Osherove said:
Sorry,
I am actually using a ListView control.

Alan
[2 quoted lines suppressed] make the
[1 quoted line suppressed] there's a
[14 quoted lines suppressed] (width
[12 quoted lines suppressed]

Hmm. IN that case I don't think there's a way
 
Back
Top