Solved

TDrawGrid..can it do this????????????????

Posted on 2002-04-12
7
233 Views
Last Modified: 2010-04-04
hihi..
  I want to use TDrawGrid to finish the following function,can it do this??????????
Wanted Function:
  When I click on a grid the color of the current grid can change. or just like :
   DrawGrid1.Rect(1,2).Color:=clBlue;
can I?????????????????????????????????????
                               wind
0
Comment
Question by:windyui
[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
  • 3
  • 2
  • 2
7 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6936251
yes, could be done,
but not in this way

DrawGrid1.Rect(1,2).Color:=clBlue;

look at the ownerdraw-features

more points, more advice

meikl ;-)
0
 
LVL 9

Accepted Solution

by:
ITugay earned 39 total points
ID: 6936404
Hi windyui,

it looks like all of yours available points :-)

meikl :-)

may be something like this?

procedure TForm1.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  with DrawGrid1 do
  begin
    if gdSelected in State then
      Canvas.Brush.Color := clLime;
    Canvas.FillRect(CellRect(ACol, ARow));
  end;
end;

----
Igor.


0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6936414
>it looks like all of yours available points :-)

guessing no,
member since 1999, question asked 10
must have thousends of points

for q lower 50 pts i gave only hints

hi igor ;-)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:ITugay
ID: 6936425
oh nooooooooo, it was a trick! :-)
0
 

Author Comment

by:windyui
ID: 6936769
Hi, Igor
   Yor are almost Right. the Currect answer is
on the ONMOUSEDOWN Event:
begin
 MouseToCell(X,Y,Col,Row);
 with DrawGrid1 do
 begin
   Canvas.Brush.Color := clLime;
   Canvas.FillRect(CellRect(ACol, ARow));
 end;
end;

0
 
LVL 9

Expert Comment

by:ITugay
ID: 6938520
hi windyui,

not very sure about your solution. Let suppose you need to show any text or graphic in cell. Then you have to write OnDrawCell implementation and the same code for OnMouseDown event. So, OnMouseDown is only partial solution, however OnDrawCell is more logical and universal one.

and I think that you code wouldn't work even if you specify DefaultDrawing = False:

1. MouseToCell(X,Y,Col,Row); should be bellow "with DrawGrid1 do"
2. you can't pass Col and Row as parameters to MouseToCell
3. after Grid will be repainted, all cell's will be white again.

to solve this problem you have to store cell's colors somewhere, let say in matrix.

------
Igor

0
 

Author Comment

by:windyui
ID: 6940124
HI,Igor
   Yes you r right.WHen other windows upon (e.g. The Message window) the Cells ,the color LOST and become white again.
   I will try to store the color in a Matrix.Thx...


                                           windyui
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to center only a line in richedit? 4 78
How to debug For loops? 3 74
Not able to call Delphi XE10 dll function from Delphi 6.0 4 56
MS Access from Delphi 31 100
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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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