473,394 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

ListView Header Color

How do I change the ListView Header Color?
If you know how to do it, please give a code example.
Adrian.

(I placed this question in another newsgroup by error.)

Feb 8 '07 #1
7 33923
What I am after (my post isn't clear) is
the background color. Standard it is
ControlLight, which I would like
to change. Hope someone can help.

Adrian.

--

P. de Ridder, drs econ., bsc psych.
Pearltree Software Development
www.pearltree.nl
www.pearltree.us
"Adrian <" <no*@home.anywherewrote in message
news:45********************@dreader2.news.tiscali. nl...
How do I change the ListView Header Color?
If you know how to do it, please give a code example.
Adrian.

(I placed this question in another newsgroup by error.)

Feb 8 '07 #2
Hi Adrian,

You need to specify OwnerDraw = true on the ListView properties and
subscribe to the DrawColumnHeader event. You are then responsible for
displaying the header information any way you chose. You also have to
subscribe to the DrawItem event and draw the list items.

When working with ownerdrawn controls, remember that the event state is a
combination of several states when testing for wether to draw a
highlighted or selected item.
On Thu, 08 Feb 2007 16:22:47 +0100, Adrian < <no*@home.anywherewrote:
What I am after (my post isn't clear) is
the background color. Standard it is
ControlLight, which I would like
to change. Hope someone can help.

Adrian.


--
Happy Coding!
Morten Wennevik [C# MVP]
Feb 9 '07 #3
How to deal with these errors?

DrawListViewItemEventArgs' could not be found
DrawListViewSubItemEventArgs' could not be found
DrawListViewColumnHeaderEventArgs' could not be found

I am referencing
System.Drawing
System.Drawing.Design

There are no other System.Drawing libraries to reference

Adrian.


"Morten Wennevik [C# MVP]" <Mo************@hotmail.comwrote in message
news:op***************@tr024.bouvet.no...
Hi Adrian,

You need to specify OwnerDraw = true on the ListView properties and
subscribe to the DrawColumnHeader event. You are then responsible for
displaying the header information any way you chose. You also have to
subscribe to the DrawItem event and draw the list items.

When working with ownerdrawn controls, remember that the event state is a
combination of several states when testing for wether to draw a
highlighted or selected item.
On Thu, 08 Feb 2007 16:22:47 +0100, Adrian < <no*@home.anywherewrote:
What I am after (my post isn't clear) is
the background color. Standard it is
ControlLight, which I would like
to change. Hope someone can help.

Adrian.


--
Happy Coding!
Morten Wennevik [C# MVP]
Feb 9 '07 #4
You don't need the Drawing namespaces, just the regular
System.Windows.Forms namespace
Upon further reading it looks like the DrawItem event isn't needed,
so using the DrawColumnHeader event and DrawSubItem event the code below
works
The code also checks
ListView lv = new ListView();
public Form1()
{
InitializeComponent();

lv.View = View.Details;
lv.OwnerDraw = true;
lv.Size = new Size(200, 100);

lv.DrawColumnHeader += new
DrawListViewColumnHeaderEventHandler(lv_DrawColumn Header);
lv.DrawSubItem += new
DrawListViewSubItemEventHandler(lv_DrawSubItem);

lv.Columns.Add("Col1");
lv.Columns.Add("Col1");
lv.Columns.Add("Col1");

this.Controls.Add(lv);

lv.Items.Add(new ListViewItem(new string[] { "One", "Two",
"Three" }));
lv.Items.Add(new ListViewItem(new string[] { "One", "Two",
"Three" }));
lv.Items.Add(new ListViewItem(new string[] { "One", "Two",
"Three" }));
}

void lv_DrawSubItem(object sender, DrawListViewSubItemEventArgse)
{
if ((e.ItemState & ListViewItemStates.Focused) 0)
{
e.Graphics.FillRectangle(SystemBrushes.Highlight,
e.Bounds);
e.Graphics.DrawString(e.Item.Text, lv.Font,
SystemBrushes.HighlightText, e.Bounds);
}
else
{
e.DrawBackground();
e.DrawText();
}
}

void lv_DrawColumnHeader(object sender,
DrawListViewColumnHeaderEventArgs e)
{
e.Graphics.FillRectangle(Brushes.GreenYellow, e.Bounds);
e.DrawText();
}


On Fri, 09 Feb 2007 13:35:50 +0100, Adrian < <no*@home.anywherewrote:
How to deal with these errors?

DrawListViewItemEventArgs' could not be found
DrawListViewSubItemEventArgs' could not be found
DrawListViewColumnHeaderEventArgs' could not be found

I am referencing
System.Drawing
System.Drawing.Design

There are no other System.Drawing libraries to reference

Adrian.


"Morten Wennevik [C# MVP]" <Mo************@hotmail.comwrote in message
news:op***************@tr024.bouvet.no...
Hi Adrian,

You need to specify OwnerDraw = true on the ListView properties and
subscribe to the DrawColumnHeader event. You are then responsible for
displaying the header information any way you chose. You also have to
subscribe to the DrawItem event and draw the list items.

When working with ownerdrawn controls, remember that the event state is a
combination of several states when testing for wether to draw a
highlighted or selected item.
On Thu, 08 Feb 2007 16:22:47 +0100, Adrian < <no*@home.anywherewrote:
>What I am after (my post isn't clear) is
the background color. Standard it is
ControlLight, which I would like
to change. Hope someone can help.

Adrian.




--
Happy Coding!
Morten Wennevik [C# MVP]
Feb 9 '07 #5

Morten ,
DrawListViewSubItemEventArgs
DrawListViewColumnHeaderEventArgs
"Could not be found" in spite of referenceing System.Windows.Forms
Adrian.
"Morten Wennevik [C# MVP]" <Mo************@hotmail.comwrote in message
news:op***************@tr024.bouvet.no...
You don't need the Drawing namespaces, just the regular
System.Windows.Forms namespace
Upon further reading it looks like the DrawItem event isn't needed,
so using the DrawColumnHeader event and DrawSubItem event the code below
works
The code also checks
ListView lv = new ListView();
public Form1()
{
InitializeComponent();

lv.View = View.Details;
lv.OwnerDraw = true;
lv.Size = new Size(200, 100);

lv.DrawColumnHeader += new
DrawListViewColumnHeaderEventHandler(lv_DrawColumn Header);
lv.DrawSubItem += new
DrawListViewSubItemEventHandler(lv_DrawSubItem);

lv.Columns.Add("Col1");
lv.Columns.Add("Col1");
lv.Columns.Add("Col1");

this.Controls.Add(lv);

lv.Items.Add(new ListViewItem(new string[] { "One", "Two",
"Three" }));
lv.Items.Add(new ListViewItem(new string[] { "One", "Two",
"Three" }));
lv.Items.Add(new ListViewItem(new string[] { "One", "Two",
"Three" }));
}

void lv_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
if ((e.ItemState & ListViewItemStates.Focused) 0)
{
e.Graphics.FillRectangle(SystemBrushes.Highlight,
e.Bounds);
e.Graphics.DrawString(e.Item.Text, lv.Font,
SystemBrushes.HighlightText, e.Bounds);
}
else
{
e.DrawBackground();
e.DrawText();
}
}

void lv_DrawColumnHeader(object sender,
DrawListViewColumnHeaderEventArgs e)
{
e.Graphics.FillRectangle(Brushes.GreenYellow, e.Bounds);
e.DrawText();
}


On Fri, 09 Feb 2007 13:35:50 +0100, Adrian < <no*@home.anywherewrote:
How to deal with these errors?

DrawListViewItemEventArgs' could not be found
DrawListViewSubItemEventArgs' could not be found
DrawListViewColumnHeaderEventArgs' could not be found

I am referencing
System.Drawing
System.Drawing.Design

There are no other System.Drawing libraries to reference

Adrian.


"Morten Wennevik [C# MVP]" <Mo************@hotmail.comwrote in message
news:op***************@tr024.bouvet.no...
Hi Adrian,

You need to specify OwnerDraw = true on the ListView properties and
subscribe to the DrawColumnHeader event. You are then responsible for
displaying the header information any way you chose. You also have to
subscribe to the DrawItem event and draw the list items.

When working with ownerdrawn controls, remember that the event state is a
combination of several states when testing for wether to draw a
highlighted or selected item.
On Thu, 08 Feb 2007 16:22:47 +0100, Adrian < <no*@home.anywherewrote:
>What I am after (my post isn't clear) is
the background color. Standard it is
ControlLight, which I would like
to change. Hope someone can help.

Adrian.




--
Happy Coding!
Morten Wennevik [C# MVP]
Feb 9 '07 #6
I have got it to run. It would not run on VS2003, but it will run on V2005.
I did make some changes though. However the header back color is read only,
so I am stuck, because specifically that I wanted to change.

Adrian

"Adrian <" <no*@home.anywherewrote in message
news:45********************@dreader2.news.tiscali. nl...
>
Morten ,
DrawListViewSubItemEventArgs
DrawListViewColumnHeaderEventArgs
"Could not be found" in spite of referenceing System.Windows.Forms
Adrian.
"Morten Wennevik [C# MVP]" <Mo************@hotmail.comwrote in message
news:op***************@tr024.bouvet.no...
You don't need the Drawing namespaces, just the regular
System.Windows.Forms namespace
Upon further reading it looks like the DrawItem event isn't needed,
so using the DrawColumnHeader event and DrawSubItem event the code below
works
The code also checks
ListView lv = new ListView();
public Form1()
{
InitializeComponent();

lv.View = View.Details;
lv.OwnerDraw = true;
lv.Size = new Size(200, 100);

lv.DrawColumnHeader += new
DrawListViewColumnHeaderEventHandler(lv_DrawColumn Header);
lv.DrawSubItem += new
DrawListViewSubItemEventHandler(lv_DrawSubItem);

lv.Columns.Add("Col1");
lv.Columns.Add("Col1");
lv.Columns.Add("Col1");

this.Controls.Add(lv);

lv.Items.Add(new ListViewItem(new string[] { "One", "Two",
"Three" }));
lv.Items.Add(new ListViewItem(new string[] { "One", "Two",
"Three" }));
lv.Items.Add(new ListViewItem(new string[] { "One", "Two",
"Three" }));
}

void lv_DrawSubItem(object sender, DrawListViewSubItemEventArgs
e)
{
if ((e.ItemState & ListViewItemStates.Focused) 0)
{
e.Graphics.FillRectangle(SystemBrushes.Highlight,
e.Bounds);
e.Graphics.DrawString(e.Item.Text, lv.Font,
SystemBrushes.HighlightText, e.Bounds);
}
else
{
e.DrawBackground();
e.DrawText();
}
}

void lv_DrawColumnHeader(object sender,
DrawListViewColumnHeaderEventArgs e)
{
e.Graphics.FillRectangle(Brushes.GreenYellow, e.Bounds);
e.DrawText();
}


On Fri, 09 Feb 2007 13:35:50 +0100, Adrian < <no*@home.anywherewrote:
How to deal with these errors?

DrawListViewItemEventArgs' could not be found
DrawListViewSubItemEventArgs' could not be found
DrawListViewColumnHeaderEventArgs' could not be found

I am referencing
System.Drawing
System.Drawing.Design

There are no other System.Drawing libraries to reference

Adrian.


"Morten Wennevik [C# MVP]" <Mo************@hotmail.comwrote in message
news:op***************@tr024.bouvet.no...
Hi Adrian,

You need to specify OwnerDraw = true on the ListView properties and
subscribe to the DrawColumnHeader event. You are then responsible for
displaying the header information any way you chose. You also have to
subscribe to the DrawItem event and draw the list items.

When working with ownerdrawn controls, remember that the event state is
a
combination of several states when testing for wether to draw a
highlighted or selected item.
On Thu, 08 Feb 2007 16:22:47 +0100, Adrian < <no*@home.anywhere>
wrote:
What I am after (my post isn't clear) is
the background color. Standard it is
ControlLight, which I would like
to change. Hope someone can help.

Adrian.

--
Happy Coding!
Morten Wennevik [C# MVP]


Feb 10 '07 #7
Sorry, you need to mention if you are running .Net 1.1 or we will assume
you are using .Net 2.0 or .Net 3.0. I don't know what you mean by
Read-Only header, the color should be whatever brush you are using when
calling Graphics.FillRectangle(Brush, e.Bounds), assuming you have set
ListView.OwnerDraw = true
On Sat, 10 Feb 2007 13:52:42 +0100, Adrian < <no*@home.anywherewrote:
I have got it to run. It would not run on VS2003, but it will run on
V2005.
I did make some changes though. However the header back color is read
only,
so I am stuck, because specifically that I wanted to change.

Adrian

"Adrian <" <no*@home.anywherewrote in message
news:45********************@dreader2.news.tiscali. nl...
>>
Morten ,
DrawListViewSubItemEventArgs
DrawListViewColumnHeaderEventArgs
"Could not be found" in spite of referenceing System.Windows.Forms
Adrian.
"Morten Wennevik [C# MVP]" <Mo************@hotmail.comwrote in message
news:op***************@tr024.bouvet.no...
You don't need the Drawing namespaces, just the regular
System.Windows.Forms namespace
Upon further reading it looks like the DrawItem event isn't needed,
so using the DrawColumnHeader event and DrawSubItem event the code below
works
The code also checks
ListView lv = new ListView();
public Form1()
{
InitializeComponent();

lv.View = View.Details;
lv.OwnerDraw = true;
lv.Size = new Size(200, 100);

lv.DrawColumnHeader += new
DrawListViewColumnHeaderEventHandler(lv_DrawColum nHeader);
lv.DrawSubItem += new
DrawListViewSubItemEventHandler(lv_DrawSubItem) ;

lv.Columns.Add("Col1");
lv.Columns.Add("Col1");
lv.Columns.Add("Col1");

this.Controls.Add(lv);

lv.Items.Add(new ListViewItem(new string[] { "One", "Two",
"Three" }));
lv.Items.Add(new ListViewItem(new string[] { "One", "Two",
"Three" }));
lv.Items.Add(new ListViewItem(new string[] { "One", "Two",
"Three" }));
}

void lv_DrawSubItem(object sender, DrawListViewSubItemEventArgs
e)
> {
if ((e.ItemState & ListViewItemStates.Focused) 0)
{
e.Graphics.FillRectangle(SystemBrushes.Highlight,
e.Bounds);
e.Graphics.DrawString(e.Item.Text, lv.Font,
SystemBrushes.HighlightText, e.Bounds);
}
else
{
e.DrawBackground();
e.DrawText();
}
}

void lv_DrawColumnHeader(object sender,
DrawListViewColumnHeaderEventArgs e)
{
e.Graphics.FillRectangle(Brushes.GreenYellow, e.Bounds);
e.DrawText();
}


On Fri, 09 Feb 2007 13:35:50 +0100, Adrian < <no*@home.anywhere
wrote:
How to deal with these errors?

DrawListViewItemEventArgs' could not be found
DrawListViewSubItemEventArgs' could not be found
DrawListViewColumnHeaderEventArgs' could not be found

I am referencing
System.Drawing
System.Drawing.Design

There are no other System.Drawing libraries to reference

Adrian.


"Morten Wennevik [C# MVP]" <Mo************@hotmail.comwrote in
message
news:op***************@tr024.bouvet.no...
Hi Adrian,

You need to specify OwnerDraw = true on the ListView properties and
subscribe to the DrawColumnHeader event. You are then responsible for
displaying the header information any way you chose. You also haveto
subscribe to the DrawItem event and draw the list items.

When working with ownerdrawn controls, remember that the event state
is
a
combination of several states when testing for wether to draw a
highlighted or selected item.
On Thu, 08 Feb 2007 16:22:47 +0100, Adrian < <no*@home.anywhere>
wrote:
>
What I am after (my post isn't clear) is
the background color. Standard it is
ControlLight, which I would like
to change. Hope someone can help.

Adrian.


--
Happy Coding!
Morten Wennevik [C# MVP]




--
Happy Coding!
Morten Wennevik [C# MVP]
Feb 12 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: andrewcw | last post by:
How is it ( or can I ) make each subitem reflect the background color ? In my case the first color is applied across the row - even though I can read the values back out correctly ? Thanks !...
5
by: Yura Moldavanov | last post by:
Hello, All! I have a problem with putting the ToolTips on ListView Header ToolTip Text Property must changes depending on column, which is under mosue cursor. Problem 1. Standatr .Net...
3
by: Simon Abolnar | last post by:
I am using VB.NET 2003 Framework 1.1 How can I get ListView header handle. I tried in this way: Dim headerHandle As IntPtr HeaderHandle=SendMessage(listView.Handle.ToInt32,...
2
by: Li Pang | last post by:
Hi, I used some code to add an arrow icon onto a listview header column for the sorting purpose. However, after the icon added, the TextAlign of the column becomes "left", if I enforced...
1
by: Lespaul36 | last post by:
I want to put an Icon on the right side of a column header when the column is clicked I found some basic code that I am trying to use, but nothing so far. Public Sub ShowHeaderIcon(ByVal colNo...
0
by: Diogo Alves - Software Developer | last post by:
Hi, I would like to put the mouse over a listview header and then display a tooltip with the description of what that header represents... How can I do that Thanks in advance. Best REgards
0
by: > Adrian | last post by:
How do I change the ListView Header Color? If you know how to do it, please give me a code example. Many thanks, Adrian
1
by: John Rogers | last post by:
Does anyone have a snippet that shows how to put the sorting arrow in the listview header? Something simple and not any of the sorting code for sorting the data. Thanks John-
0
by: palash909 | last post by:
Visual basic version(2008) How can i change the listview column header color and font size?? 1. Listview1 body font color is black 2.Font size 9 and style is regular ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.