Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7194985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:29:12+00:00 2026-05-28T20:29:12+00:00

I have ListView (vsReport) and StringGrid and what I want is if I click

  • 0

I have ListView (vsReport) and StringGrid and what I want is if I click on some element in ListView, particular cells in StringGrid have to change colors. How do I do it?

Path is filled with 1 (move up) and 0(move right), it starts in left bottom and ends in right top corner, and I have to color these cells.


Thanks for the answers, I handled with my problem, but there’s another little issue, how can I leave text in cells visible? FillRect fills the entire cell.

procedure TForm1.ListView1SelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
var aRect: TRect;
     a,x,y:integer;
     path:string;
begin
  path:=ListView1.Items[Item.Index].Caption;

  x:=0;
  y:=StringGrid1.RowCount;
for a := 0 to length(path) do
  begin
   if path[a]='1' then y:=y-1 else x:=x+1;
   aRect := StringGrid1.CellRect(x-1,y-1);
   StringGrid1.Canvas.Brush.Color := clBlue;
   StringGrid1.Canvas.FillRect(aRect);
   end;
end; 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:29:13+00:00Added an answer on May 28, 2026 at 8:29 pm
    1. Realize that a cell’s color change should be permanent, so that when the StringGrid is painted again, e.g. when the StringGrid was obfuscated by a dialog, also the special colors should be painted again.
    2. Thus you need to store the desired colors somewhere. Say you want to use an array for that, then make a choice between:
      • Storing the special colors along with the grid coordinates in a one-dimensional array. This is good for memory usage, but you would need to search this entire array for the specific coordinate which the StringGrid’s OnDrawCell handler (see step 3) provides,
      • Storing only the special colors in a two-dimensional array. This is good for speed when drawing, but you need to synchronize the array’s column and row bounds to that of the StringGrid,
      • Or, when you do not need the Objects property of the StringGrid for any purpose, you could employ this property for color storage by typecasting the color to and from a TObject. Shout if you need help with that.
    3. Paint the colored cells in a StringGrid’s OnDrawCell event handler (search here on Stack Overflow for [Delphi] StringGrid OnDrawCell when in need of assistance with that).
    4. The ListView’s OnSelectItem event exposes the Item which is clicked or otherwise selected.
    5. Retrieve necessery information from that item or its sub-items to determine which cell is to be changed in what color.
    6. Add that information to the chosen storage solution of step 2.
    7. Realize that when all painting now is done “automatically”, just a call to StringGrid.Repaint should be enough.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have listview with some listadapter after click on item from list I'd like
Hi I have ListView and I want to delete all the element in runtime.How
I have ListView with about 30 items. When I click on an item, some
I have listview having customized some textview and one imageview. When I long click
I want to have one ListView that when I click on the item the
I have a ListView with a GridView with 3 columns. I want last column
I have ListView. Every row has TextView with some text. And also by default
I have a ListView that is filled with items of an ArrayAdapter. Now I
I have a ListView that contains 3 checkboxes per row. I want to set
I have a ListView which displays information about some entities (all of the same

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.