473,327 Members | 2,012 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,327 software developers and data experts.

ListView Custom Draw

Hello there,
Wonder can anyone point me in the correct direction?
I would like to change the standard list view control so that i can have
alternated rows in a different color, i.e. white grey white grey
And I'd also like to change the color or the first colmn.

What is the best approach for same?

thanks
Brian
Nov 16 '05 #1
5 12453
check this article..

http://www.codeproject.com/cs/miscctrl/customheader.asp

--
rajagopal

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #2
thanks i'll have a look at that
brian

"Rajagopal Pasupuleti" wrote:
check this article..

http://www.codeproject.com/cs/miscctrl/customheader.asp

--
rajagopal

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #3
Hi agian,
I see that this sample uses owner draw,
what i really would like is to use custom draw like i did in my native c++
application.
any ideas on how i can do this in .NET?

Thanks

"Rajagopal Pasupuleti" wrote:
check this article..

http://www.codeproject.com/cs/miscctrl/customheader.asp

--
rajagopal

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #4
Hi Brian,

The *approach* is the same as in C++ - you will just have more hassle with
C# due to all this P/Invoke stuff.
I did it myself so I can claim this is possible :-)

As far as I remember, the main idea is to handle certain ListView
notification messages (CDDS_PREPAINT and CDDS_POSTPAINT) to let the control
know you are going to do some ownerdraw. I also remember there were several
modes possible - full owner-draw, owner draw for a particular column and so
on. The most complex thing is obviously handling the notification messages
and juggling with all these API structures in C# - so you will need a solid
background in P/Invoke.

Your first step will be to override the WndProc method in a control
inherited from the ListView and to react on the NM_CUSTOMDRAW message:

protected override void WndProc(ref Message message)
{
base.WndProc(ref message);

switch (message.Msg)
{
case (int)Win32API.CommonControls.OCM_NOTIFY:
Win32API.CommonControls.NMHDR msgHeader =
(Win32API.CommonControls.NMHDR)message.GetLParam(t ypeof(Win32API.CommonControls.NMHDR));

switch (msgHeader.code)
{
case (int)Win32API.CommonControls.NM_CUSTOMDRAW:
// Do the custom drawing.
break;
default:
break;
}

break;

default:
break;
}
}

The Win32API.CommonControls namespace was my own one - you will have to
declare your own constants and structures.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Brian Keating EI9FXB" <csharp at briankeating.net> wrote in message
news:2C**********************************@microsof t.com...
Hi agian,
I see that this sample uses owner draw,
what i really would like is to use custom draw like i did in my native c++
application.
any ideas on how i can do this in .NET?

Thanks

"Rajagopal Pasupuleti" wrote:
check this article..

http://www.codeproject.com/cs/miscctrl/customheader.asp

--
rajagopal

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 16 '05 #5
Hi Dmitriy,

Excellent, I started doing this yesterday myself and am making progress,
many thanks for excellent reply, i'm now confident i'm on the right road.

thanks again
brian

"Dmitriy Lapshin [C# / .NET MVP]" wrote:
Hi Brian,

The *approach* is the same as in C++ - you will just have more hassle with
C# due to all this P/Invoke stuff.
I did it myself so I can claim this is possible :-)

As far as I remember, the main idea is to handle certain ListView
notification messages (CDDS_PREPAINT and CDDS_POSTPAINT) to let the control
know you are going to do some ownerdraw. I also remember there were several
modes possible - full owner-draw, owner draw for a particular column and so
on. The most complex thing is obviously handling the notification messages
and juggling with all these API structures in C# - so you will need a solid
background in P/Invoke.

Your first step will be to override the WndProc method in a control
inherited from the ListView and to react on the NM_CUSTOMDRAW message:

protected override void WndProc(ref Message message)
{
base.WndProc(ref message);

switch (message.Msg)
{
case (int)Win32API.CommonControls.OCM_NOTIFY:
Win32API.CommonControls.NMHDR msgHeader =
(Win32API.CommonControls.NMHDR)message.GetLParam(t ypeof(Win32API.CommonControls.NMHDR));

switch (msgHeader.code)
{
case (int)Win32API.CommonControls.NM_CUSTOMDRAW:
// Do the custom drawing.
break;
default:
break;
}

break;

default:
break;
}
}

The Win32API.CommonControls namespace was my own one - you will have to
declare your own constants and structures.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Brian Keating EI9FXB" <csharp at briankeating.net> wrote in message
news:2C**********************************@microsof t.com...
Hi agian,
I see that this sample uses owner draw,
what i really would like is to use custom draw like i did in my native c++
application.
any ideas on how i can do this in .NET?

Thanks

"Rajagopal Pasupuleti" wrote:
check this article..

http://www.codeproject.com/cs/miscctrl/customheader.asp

--
rajagopal

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 16 '05 #6

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

Similar topics

4
by: VM | last post by:
Can I add text of different colors to a listview? Let's say I want to add, on one line, the text "This is my message" on my listview. Would it be possible to add this sentence to the listview...
0
by: Steve | last post by:
I'm using CustomDraw to draw my listview item but there seems to be some basic characteristics of the draw operation that Windows refuses to allow you to change. 1) I want to most the position of...
0
by: Gino | last post by:
Hi, Is there any ways to custom draw the property grid? for example, I would like to change some property's background color or font color while these property have different states. any...
2
by: Benny Raymond | last post by:
How would you go about custom drawing the title bar of a form? I'd like to change it so that I can add different colors to my title and also change how the close button works (since I override it...
3
by: Arnold the Aardvark | last post by:
I am creating a custom draw tree view based on CTreeCtrl. When the control is re-sized the background is blanked completely, resulting in a horrible flicker. I've seen various suggestions...
1
by: Stefano Baldi | last post by:
I'm trying to change highlight color af a ListItem Here's my function Private Sub ListViewCustomDraw(ByRef m As System.Windows.Forms.Message) Dim lvcd As NMLVCUSTOMDRAW Dim...
1
by: Curious | last post by:
Hi, I have a listview with the View property set as Details. I have set 4 columns, and now I am trying to set some Icons on the column headers. Is this possible? Thanks in Advance
5
by: --== Alain ==-- | last post by:
Hi, Several months ago i've asked some information about the best way how to have some particular columns (progress bar, checkbox, images, color picker,...) in a ListView component. It seems...
5
by: Mark Olbert | last post by:
How do I get the DataPager and ListView to play nice together when I use a custom datasource? In my webpage, I use linq to pull data from a SqlServer database and assign the resulting...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.