Jump to content


Photo

CheckBox Column with Check-All Functionality


  • Please log in to reply
7 replies to this topic

#1 Uwe Raabe

Uwe Raabe
  • Members
  • 9 posts
  • Gender:Male

Posted 06 May 2020 - 10:29 AM

I have a requirement for a CheckBox column with a checkbox placed in the header with the following functionality:

  • When all rows in this column are checked, the header checkbox shows checked
  • When any row in this column is unchecked, the header checkbox shows unchecked
  • When the header checkbox is unchecked and clicked, all rows in that column are checked
  • When the header checkbox is checked and clicked, all rows in that column are unchecked

Currently I handle this by using an image for the header checkbox and change that according to the state, but that has some drawbacks:

  • The image in the header is not identical to the checkbox in the grid rows
  • I can only react on the header click and not on the header image click. This contrasts to the checkbox click in the rows, where I have to click on the checkbox while a click on the rest of the cell is ignored

Perhaps I am missing something?

 

On the other hand I would file this as a feature request for the CheckBox column  :)



#2 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 7,880 posts
  • Gender:Male

Posted 06 May 2020 - 03:50 PM

Hi,

 

Can you maybe attach small demo (one column) here so I can adjust it and send you back. Maybe I can see what's wrong.


boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Members Section: bms.bergsoft.net
Articles and Tutorials: dn.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#3 Uwe Raabe

Uwe Raabe
  • Members
  • 9 posts
  • Gender:Male

Posted 06 May 2020 - 05:27 PM

No problem. Attached is a demo project with two of those columns.

 

Don't get me wrong - it is working (almost) as expected. I just would prefer a bit simpler implementation.

Attached Files



#4 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 7,880 posts
  • Gender:Male

Posted 07 May 2020 - 12:28 AM

Hi,

 

It seems that you forgot to attach ;) If the forum is problematic, you cans end it to my e-mail


boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Members Section: bms.bergsoft.net
Articles and Tutorials: dn.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#5 Uwe Raabe

Uwe Raabe
  • Members
  • 9 posts
  • Gender:Male

Posted 07 May 2020 - 04:50 PM

Strange. I was pretty confident I did. Never mind. Now I have attached the file to my previous post and I can even see it there.



#6 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 7,880 posts
  • Gender:Male

Posted 07 May 2020 - 07:50 PM

Hi,

 

For drawing checkbox in same style as checkboxes in the grid, you can use next event:

 

Set doContent inside Column.Header.DrawingOptions to False and doCustom to True;

 

procedure TMainForm.grdDokumenteCustomDrawHeader(Sender: TObject;
  Index: Integer; HeaderRect: TRect; HeaderState: TNxButtonState);
var
  MyCheckBoxRect: TRect;
begin
  if Index = colArchive.Index then
  begin
    MyCheckBoxRect := HeaderRect;
    MyCheckBoxRect.Offset(8, 2);
    MyCheckBoxRect.Height := 14;
    MyCheckBoxRect.Width := 14;
 
    grdDokumente.StylePaint.Canvas := grdDokumente.Canvas;
    grdDokumente.StylePaint.PaintCheckBox(MyCheckBoxRect, cbChecked, []);
  end;
end;

 

But as I only have one event for custom drawing of header, background need to be drawn too :( I'm thinking about adding another event called OnCustomDrawHeaderContent that will let you keep default drawing of Header but you can draw other things as custom drawing.

 

Second problem you have, if I understood you want to be able to register only clicks inside checkbox?


boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Members Section: bms.bergsoft.net
Articles and Tutorials: dn.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#7 Uwe Raabe

Uwe Raabe
  • Members
  • 9 posts
  • Gender:Male

Posted 14 May 2020 - 10:29 AM

Thanks, I appreciate your effort to find a solution.

 

Do you see any way to encapsulate the whole functionality inside a class helper for or descendant of TNxCheckBoxColumn6?

In my use case I have two columns with this requirement and I tried to separate the code into a new unit which I just have to use to get the requested behavior. The problem I have is that I don't know how I can iterate the cell values when I don't have access to the grid instance from inside the column class.



#8 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 7,880 posts
  • Gender:Male

Posted 14 May 2020 - 04:50 PM

Hi,

This can be nice idea actually. I will think about it. Maybe at first I can add CheckAll/UncheckAll functionality.


boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Members Section: bms.bergsoft.net
Articles and Tutorials: dn.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users