|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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? |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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:
|
|
#5
|
|||
|
|||
|
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. |
|
#6
|
||||
|
||||
|
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 |
|
#7
|
|||
|
|||
|
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 ?? |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Delphi Programming > StringGrid Canvas distorts Mouse Selection |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|