Jump to content


Photo

Hide cell based on databound field.


  • Please log in to reply
7 replies to this topic

#1 FourWhey

FourWhey
  • Members
  • 165 posts

Posted 28 September 2016 - 11:46 PM

I have a TNxDBGrid6, with columns that are databound, and one that is not that's an icon column.  I'd like to show/hide the icon column cells based on the value of another hidden databound column within the same row of the grid.

 

it would look like this if it worked.

 

Date, Icon, (hidden column = x)

Date, NoIcon, (hidden column = y)

Date, Icon, (hidden column = x)

Date, Icon, (hidden column = x)

Date, Icon, (hidden column = x)

Date, NoIcon, (hidden column = z)

 

This is what I tried, but it didn't work. Even if the cell is Visible = False the icon is still shown.

 

Is there a way to do this?

procedure TFormNotesDlg.colIconSetCell(Sender: TObject; ACol,
  ARow: Integer; Cell: INxBaseCell);
var
  DateCol, TypeCol: Integer;
begin
  inherited;
  DateCol := Grd.Columns.ItemBy['colDisplayDate'].Index;

  Cell.Visible := False;
  TypeCol := Grd.Columns.ItemBy['colNoteType'].Index;
  if (Grd.Cell[TypeCol, ARow].AsString = 'CALL') then
    Cell.Visible := True;
end;


#2 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 30 September 2016 - 03:06 AM

Hi,

Try with Empty property of Cell. I hope it work in your case, if not I will tweak it and make it work.

I'm working on implementing Visible property. This is feature from this post:
http://www.bergsoft....ic=4455&p=18759

You hide cell and grid spread visible one over the hidden cell.

Empty property is setting cell as "empty" (not drawing content).
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.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 FourWhey

FourWhey
  • Members
  • 165 posts

Posted 30 September 2016 - 06:46 PM

Okay, I'll give Empty a try.

 

Thank you as always.



#4 FourWhey

FourWhey
  • Members
  • 165 posts

Posted 30 September 2016 - 10:06 PM

This doesn't work, the icon column is still shown. Maybe I'm doing it at the wrong time?  I'm setting it in the column I want to be able to toggle, using its SetCell event.

procedure TFormNotesDlg.colCallIconSetCell(Sender: TObject; ACol, ARow: Integer; Cell: INxBaseCell);
begin
  inherited;
  if (GrdNotes.Cell[GrdNotes.Columns.ItemBy['colNoteType'].Index, ARow].AsString <> 'CALL') then
    Cell.Empty := True;
end;

Also, if I set a column to be Visible = False at design time, it doesn't respect that at run time.

 

http://imgur.com/a/FMjmI

 

Edit: I've noticed that the Visibility issue happens at design time too when I set the Query.Active = True.  Something about what it's doing when the query is opened is overriding the values I've set previously.  I'm investigating why.

 

Edit: I had dboUseFieldProperties set to True, which I guess doing what it was doing is intended in that case.



#5 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 01 October 2016 - 09:46 AM

Hi,

I will test it in next couple of days. Hoping that I will release new update in Monday.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.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.

#6 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 01 October 2016 - 09:30 PM

I forgot to mention HideWhenEmpty property of Column which need to be set to True. If you have time, please try it too.

I will test about Visible of Column too.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.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 FourWhey

FourWhey
  • Members
  • 165 posts

Posted 03 October 2016 - 01:21 AM

 

I will test about Visible of Column too.

 

Well, it might not be a bug. It really depends on whether or not you want dboUseFieldProperties to override a column's visible property when manually set.

 

In the case of the field being marked as hidden, the column would inherit that from the field, which might be nice.  When experimenting, I tried setting the Field.Visible = False in Grid.OnGetField and it threw an error. It's why I had dboUseFieldProperties = True set in the first place, I just forgot to undo it.



#8 FourWhey

FourWhey
  • Members
  • 165 posts

Posted 03 October 2016 - 01:22 AM

I forgot to mention HideWhenEmpty property of Column which need to be set to True. If you have time, please try it too.

 

This worked.  Thank you again.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users