Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 21st, 2004, 02:59 PM
Villas1k Villas1k is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 5 Villas1k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 30 sec
Reputation Power: 0
StringGrid Canvas distorts Mouse Selection

Hi,

In a C++Builder project I am using a StringGrid component. When the user selects multiple cells using a mouse, logically the StringGrid Object displays the blue selection area.

Then, I have painted every all rows so by using the following code:

StringGrid1->Canvas->FillRect etc. etc.

But this caused a problem. Now the selection area (box) is not visible. And also the content of the cells are not visible.

Now I understand that the content is not visible and the canvas object has a function to fill text. So that is not a problem, but when the user selects multiple cells (using the mouse), the selection area remains behind the colored Canvas.

What can I do about this?

Reply With Quote
  #2  
Old July 22nd, 2004, 10:38 AM
Canderel Canderel is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 40 Canderel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Are you overriding the default OnDrawCell() event?

If you are, why? Though I assume you have a good reason.

Making your own OnDrawCell() event is (obviously) not impossible, but I've never been able to do it with a great deal of success.

Give us some more info.

Reply With Quote
  #3  
Old July 22nd, 2004, 03:34 PM
Villas1k Villas1k is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 5 Villas1k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 30 sec
Reputation Power: 0
If you mean that the code is in OndrawCell()

Hi,

If you mean that if I have the code in the OnDrawCell(), Yes. I wouldn't know any other way to do it.

I would appreciate if you can help me on this if I am going the wrong way with this.

Thanks,

Armando

Reply With Quote
  #4  
Old July 26th, 2004, 03:16 AM
Canderel Canderel is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 40 Canderel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
First, you have to disable DefaultDrawing on your grid then. This really makes that the grid is useless, but I searched the net, and found this piece of funky code, which basically redo's what the default drawing does, except now you can control it.

The code was found on http://www.cppbuilderdevjournal.com...tring_grids.htm
and I believe you may use it freely.

Note that some of it is for my formatting purposes (the 5th column is in bold and right aligned) etc. Though you could add colours and much more the same way.

Btw. My name is Reenen, and I marked my additions to the code.

PHP Code:
 void __fastcall TMainForm::BigGridDrawCell(TObject *Senderint ACol,
      
int ARowTRect &RectTGridDrawState State)
{
  
TStringGridStringGrid 
    
static_cast<TStringGrid*>(Sender);
  
assert(StringGrid != NULL);

  
TCanvasSGCanvas =StringGrid->Canvas;
  
SGCanvas->Font StringGrid->Font;

  
RECT RText static_cast<RECT>(Rect);
  const 
AnsiString text(
    
StringGrid->Cells[ACol][ARow]);

  const 
bool fixed =
    
State.Contains(gdFixed);
  const 
bool focused =
    
State.Contains(gdFocused);
  
//Reenen's Addition
  
const bool BoldCol = (ARow !=0) && (ACol == 5);

  
bool selected =
    
State.Contains(gdSelected);
  if (!
StringGrid->Options.Contains(
    
goDrawFocusSelected)) {
    
selected selected && !focused;
  }
  
// if the cell is fixed (headers)
  
if (fixed) {
    
SGCanvas->Brush->Color =
      
StringGrid->FixedColor;
    
SGCanvas->Font->Color clBtnText;
    
SGCanvas->FillRect(Rect);
    
Frame3D(SGCanvasRect,
      
clBtnHighlightclBtnShadow1);
  }
  
// if the cell is selected
  
else if (selected) {
    
SGCanvas->Brush->Color =clHighlight;
    
SGCanvas->Font->Color =
      
clHighlightText;
    
SGCanvas->FillRect(Rect);
  }
  
// if the cell is normal
  
else {
    
SGCanvas->Brush->Color =
      
StringGrid->Color;

    
//Reenen's Addition
    
if (BoldCol)
      
SGCanvas->Font->Style TFontStyles() << fsBold;
    else
      
SGCanvas->Font->Style TFontStyles();


    
SGCanvas->Font->Color =
      
StringGrid->Font->Color;
    
SGCanvas->FillRect(Rect);
  }
  
// if the cell is focused
  
if (focused) {
    
DrawFocusRect(
      
SGCanvas->Handle, &RText);
  }

  
//Reenen's Addition
  
const int AllignmentFlag = (ARow!=0)&&(ACol==5) ? DT_RIGHT DT_LEFT;
  
// draw the text
  
RText.left += 2RText.top += 2RText.right -= 2;
  
DrawText(SGCanvas->Handle,
    
text.c_str(), text.Length(), &RText,
    
AllignmentFlag |DT_VCENTER |DT_SINGLELINE); 

Reply With Quote
  #5  
Old July 27th, 2004, 09:59 AM
Villas1k Villas1k is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 5 Villas1k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 30 sec
Reputation Power: 0
Arrow Previous solution seems to be too complicated, but

Hi,

The previous solution seems to be too complicated, but I found a solution earlier, but couldn't transmit it until now.

My solution is the same as above, but much simpler, in the code which draw the background of the cells, a simple conditional statement is placed:

if(!(State.Contains(gdSelected)))
{
//Code for drawing the background of the cells.
.....
}

The DrawCell event fires anytime the grid changes or if showed, and this happens so often that the code above would take care of any problem.

The code essentially says, that if a cell is selected, don't draw in it. This way the selection box is always visible!

Altough the previous answer's code is correct it assumes too much, but this is due to the fact that the replier does not have all the info. Thanks anyway. And thanks you all for your input.

Armando.

Reply With Quote
  #6  
Old July 27th, 2004, 08:28 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Click here for more information.
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,713 Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Days 11 h 21 m 11 sec
Reputation Power: 1179
Come to think of it, I wrote code similar to Canderel's post 5+ years ago. I actually did all the drawing by myself -- just couldn't dig up that code which is why I didn't post it.
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month

Reply With Quote
  #7  
Old March 30th, 2005, 07:20 PM
Nice Nice is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 48 Nice User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 24 m 10 sec
Reputation Power: 4
I am also populating StringGrid using OnDrawCell event. It populates the cells correctly; but when I click on a cell, the content of the cell disappears.

Any clue anyone ??

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > StringGrid Canvas distorts Mouse Selection


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT