Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Adding Checkboxes inside StringGrids.

mydelphimydelphi Member Posts: 62
Checkboxes inside StringGrids.
Checkboxes to StringGrids.
Checkboxes to a grid

Checkboxes are becoming more and more of a desire to add
into a stringgrid or some form of grid control. Without having
to resort to other peoples works (shareware/freeware controls)
I want to see if I could build my own. So ...

I've search around and never really found anything that would
work the way I wanted in terms of checkboxes inside string grids.
The closest I found was inside this one link below, where some
one was helping out a similar request. I wasn't able to get mine
to work, so I gave it a shot to the best of my ability.

http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_20539050.html

Ok. Here's how it is. I have managed to figure out how to add
checkboxes inside a TStringGrid control on my form. Basically, I
followed the code (above) as a template and tweaked it with my
own ideas. The result was Checkboxes in each row that I had
assigned, usually within a column of course.

Here is an actual scenario to help illustrate what I want to do.

Select | Name | Aprove
========================
[x] 01 | Files | Sign |
------------------------
[x] 02 | CDr | Sign |
------------------------
[x] 03 | CDr | Sign |
------------------------
[x] 04 | Files | Sign |
------------------------
[ ] 05 | none | N/A |

In the example above, you see 5 rows of columned data filled in.
And in each row, 1-4, are checked, while the 5th row is not.
Inside my app, I want to check each of column 1's checkbox
value for cbChecked and then perform an action on each.
Since column 1's row 5 is chUnchecked, no action is required.

At any time, I or the user can uncheck any of the checkboxes.
The checkboxes basically tell me what items I can apply the
action on.

Now, my problem is, that I can't figure out how to access the
individual checkboxes. In the source code (above link) you
see a reference to Chk as being a TCheckBox control added
to the stringgrid list. It seems that once they are created,
only the last one is remembered. Even though I can access
them with the mouse and click any one of them, when inside
my code, I can't access them. In other words, there's no
way to call something like this:

if StringGrid1.Chk.cells[1,R].state = cbChecked then doAction

Can someone help me out with this. I'm completly stumped
over this one.

Thank you all.

-mydelphi

Comments

  • zibadianzibadian Member Posts: 6,349
    : Checkboxes inside StringGrids.
    : Checkboxes to StringGrids.
    : Checkboxes to a grid
    :
    : Checkboxes are becoming more and more of a desire to add
    : into a stringgrid or some form of grid control. Without having
    : to resort to other peoples works (shareware/freeware controls)
    : I want to see if I could build my own. So ...
    :
    : I've search around and never really found anything that would
    : work the way I wanted in terms of checkboxes inside string grids.
    : The closest I found was inside this one link below, where some
    : one was helping out a similar request. I wasn't able to get mine
    : to work, so I gave it a shot to the best of my ability.
    :
    : http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q
    : _20539050.html
    :
    : Ok. Here's how it is. I have managed to figure out how to add
    : checkboxes inside a TStringGrid control on my form. Basically, I
    : followed the code (above) as a template and tweaked it with my
    : own ideas. The result was Checkboxes in each row that I had
    : assigned, usually within a column of course.
    :
    : Here is an actual scenario to help illustrate what I want to do.
    :
    : Select | Name | Aprove
    : ========================
    : [x] 01 | Files | Sign |
    : ------------------------
    : [x] 02 | CDr | Sign |
    : ------------------------
    : [x] 03 | CDr | Sign |
    : ------------------------
    : [x] 04 | Files | Sign |
    : ------------------------
    : [ ] 05 | none | N/A |
    :
    : In the example above, you see 5 rows of columned data filled in.
    : And in each row, 1-4, are checked, while the 5th row is not.
    : Inside my app, I want to check each of column 1's checkbox
    : value for cbChecked and then perform an action on each.
    : Since column 1's row 5 is chUnchecked, no action is required.
    :
    : At any time, I or the user can uncheck any of the checkboxes.
    : The checkboxes basically tell me what items I can apply the
    : action on.
    :
    : Now, my problem is, that I can't figure out how to access the
    : individual checkboxes. In the source code (above link) you
    : see a reference to Chk as being a TCheckBox control added
    : to the stringgrid list. It seems that once they are created,
    : only the last one is remembered. Even though I can access
    : them with the mouse and click any one of them, when inside
    : my code, I can't access them. In other words, there's no
    : way to call something like this:
    :
    : if StringGrid1.Chk.cells[1,R].state = cbChecked then doAction
    :
    : Can someone help me out with this. I'm completly stumped
    : over this one.
    :
    : Thank you all.
    :
    : -mydelphi

    I would add an array field to the grid and store the checkboxes in that. That way you can add a new property to access them from outside the grid.
  • mydelphimydelphi Member Posts: 62
    Well, I've done it! Although it wasn't easy, I
    figured it out. For the time being, the code is
    messy spagetti. But now, I can click on a cell
    with a checkbox to check/uncheck at user request.

    http://img228.imageshack.us/img228/5862/mydelphiexampledemo1verry6.png

    Select | Name | Aprove
    ========================
    [x] 01 | Files | Sign |
    ------------------------
    [x] 02 | CDr | Sign |
    ------------------------
    [x] 03 | CDr | Sign |
    ------------------------
    [x] 04 | Files | Sign |
    ------------------------
    [ ] 05 | none | N/A |


    [ RUN Action ] <--- the run button


    So, when the user is ready to run the
    process, any columns that have a box
    that is [x] checked will be processed.

    -mydelphi
  • mydelphimydelphi Member Posts: 62
    zibadian wrote:

    >> I would add an array field to the grid and store the checkboxes in
    >> that. That way you can add a new property to access them from outside
    >> the grid.

    I'm not sure how to add an array field to a grid. Sounds too complicated.
    But then again, I was able to acomplish the above demo (see pic link).

    But, I think I have an idea of how to keep track of the check boxes.
    But thanks for your suggestion.

    There are other things to fix in ths demo app, like the way it
    seems to keep a highlighted retangle, or when outside of the
    control (ie, in another control) the cell is highlighted all blue.

    About the only thing that worries me is having any possible mem leaks
    while using the method inside this app (partial code from link, above).
    If there is a way to test this, I'd be greatly appreciated.

    If I can find an upload site to upload the demo, I'll post a link,
    for now, its taken me over 2 hours just to find, upload, and post
    an image. Lots of slow work over dialup. The app is only 30k in
    size.

    -mydelphi
  • zibadianzibadian Member Posts: 6,349
    : zibadian wrote:
    :
    : >> I would add an array field to the grid and store the checkboxes in
    : >> that. That way you can add a new property to access them from
    : outside
    : >> the grid.
    :
    : I'm not sure how to add an array field to a grid. Sounds too
    : complicated.
    : But then again, I was able to acomplish the above demo (see pic
    : link).
    :
    : But, I think I have an idea of how to keep track of the check boxes.
    : But thanks for your suggestion.
    :
    : There are other things to fix in ths demo app, like the way it
    : seems to keep a highlighted retangle, or when outside of the
    : control (ie, in another control) the cell is highlighted all blue.
    :
    : About the only thing that worries me is having any possible mem leaks
    : while using the method inside this app (partial code from link,
    : above).
    : If there is a way to test this, I'd be greatly appreciated.
    :
    : If I can find an upload site to upload the demo, I'll post a link,
    : for now, its taken me over 2 hours just to find, upload, and post
    : an image. Lots of slow work over dialup. The app is only 30k in
    : size.
    :
    : -mydelphi

    Adding an field to a component is just as simple as adding a field to an object, since components are ultimately objects.
    Here's an example:
    [code]
    type
    TIntGrid = class(TStringGrid)
    private
    FCheckBoxes: array of TCheckbox;
    function GetCheckBoxes(Row: integer): TCheckbox;
    public
    property CheckBoxes[Row: integer]: TCheckboxread GetCheckBoxes;
    end;
    [/code]
    Obviously maintaining the array is a little bit more difficult. That requires keeping track of some indexes and growing and shrinking the array.
Sign In or Register to comment.