473,566 Members | 3,004 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 12482
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(re f message);

switch (message.Msg)
{
case (int)Win32API.C ommonControls.O CM_NOTIFY:
Win32API.Common Controls.NMHDR msgHeader =
(Win32API.Commo nControls.NMHDR )message.GetLPa ram(typeof(Win3 2API.CommonCont rols.NMHDR));

switch (msgHeader.code )
{
case (int)Win32API.C ommonControls.N M_CUSTOMDRAW:
// Do the custom drawing.
break;
default:
break;
}

break;

default:
break;
}
}

The Win32API.Common Controls 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.ne t> wrote in message
news:2C******** *************** ***********@mic rosoft.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(re f message);

switch (message.Msg)
{
case (int)Win32API.C ommonControls.O CM_NOTIFY:
Win32API.Common Controls.NMHDR msgHeader =
(Win32API.Commo nControls.NMHDR )message.GetLPa ram(typeof(Win3 2API.CommonCont rols.NMHDR));

switch (msgHeader.code )
{
case (int)Win32API.C ommonControls.N M_CUSTOMDRAW:
// Do the custom drawing.
break;
default:
break;
}

break;

default:
break;
}
}

The Win32API.Common Controls 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.ne t> wrote in message
news:2C******** *************** ***********@mic rosoft.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
2756
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 with the word "This" in one color, "is" in another color, and so on? Then in my next row, I'd add another sentence with more different colors....
0
1559
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 the label field. I know that I can technically draw it whereever I choose, but Windows handles mouse clicks different depending on where you click on...
0
1268
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 suggestions? Thanks
2
16264
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 and cause the form to minimize). Thanks in advance, Benny
3
7212
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 involving the use of double buffering. Those are fine but I want to understand what is wrong. When I created the same control in C++Builder the view was...
1
2183
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 oListViewItemEx As ListViewItemEx
1
1944
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
1792
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 that ListView is a complex component and a lot of people advise to build a custom component but not from ListVIew itself. Some use a datagrid...
5
9519
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 IEnumerable<to the ListView's Datasource property. This all works fine to display the first 3 items (the DataPager is set to display three items at a time), but...
0
7584
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7893
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8109
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2085
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.