Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Color in ListView

Posted on 1999-06-22
8
Medium Priority
?
366 Views
Last Modified: 2010-04-06
How do I set the color of one or more rows (not all!) in a ListView?
0
Comment
Question by:jonassondaniel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 3

Expert Comment

by:Slavak
ID: 1384013
Set OwnerDraw to True and write OnCustomDraw event code.

0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1384014
slavak.
smartie.
tell jonassondaniel where he can find property OwnerDraw in TListView...

BlackDeath.
0
 
LVL 3

Expert Comment

by:Slavak
ID: 1384015
Hi, Black.

TListView OwnerDraw property exist in D4. If you use previsious version of Delphi you can see the source for D4 TListView. If need I can do it for you.

Regards,
  Slava.
 

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:jonassondaniel
ID: 1384016
Hmm.. I know what you're talking about.. but I don't think I'll manage to do it on my own... If you could provide some code for changing the color of a certain row in a ListView control I'd be really happy.. I have increased the points for your trouble (if you decide to help...).

(What I'm trying to do is a simple filemanager and I want to associate a certain color to files with same extension.)
0
 
LVL 3

Accepted Solution

by:
Slavak earned 150 total points
ID: 1384017
Hi,

This code for D4 users.

You need override OnCustomDrawItem event :

procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
  Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
 // you need check Item.Caption for file extension
 // instead of Item.Index
 If Item.Index mod 2 = 0
  Then ListView1.Canvas.Brush.Color := clSilver
  Else ListView1.Canvas.Brush.Color := clAqua;

 DefaultDraw := True;
end;

Regards.

0
 

Author Comment

by:jonassondaniel
ID: 1384018
I tried what you are suggsting but it doesn't seem to work. Do I need to do something more than what you're describing perhaps?
0
 
LVL 3

Expert Comment

by:Slavak
ID: 1384019
I don't know what to say.
I just now made new application, droped TListView on form and ovveride the OnCustomDrawItem event with code above.
And this is working.

I have english Delphi 4 Client/Server with update 3.

Do you have another version of Delphi?


0
 

Author Comment

by:jonassondaniel
ID: 1384020
I tried again (with a new app) and now it works. Strange.. I did exactly the same way as last time.. ..but well it works and I'm happy!  Thanks!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question