Recent

Author Topic: using cbsellipsis  (Read 1803 times)

mtanner

  • Sr. Member
  • ****
  • Posts: 287
using cbsellipsis
« on: March 29, 2018, 11:26:50 pm »
In a TDragrid I am trying to use a cbsEllipsis cell editor. In the button click method I call a TCalendar dialog. The initial date is obtained from my appkications data structures based on the row, and the value returned from the TCalendar dialog is wriitn into the data structures. This much works ok.

What I cannot find out how to do is display the cell contents in the edit part of cbsEllipsis. When the editor is invoked (in OnSelectEditor) I want to put the current cell contents in the cbsEllipsis display, and on return from (in this case the TCalendar call) to display the results in the cbsEllipsis, before the cell becomes unselected.

Currently the new cell contents are displayed properly when the cell is unselected, (done by my OnDrawCell routine), but until then the cbsEllipsisi display is blank.

I've read all the reference material I can find on using cell editors, but none of them explain how to do this.  I'm probably just missing soke simple bit of information, but I cannot progress any further/

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: using cbsellipsis
« Reply #1 on: March 30, 2018, 12:20:14 am »
This works for me:
Code: Pascal  [Select][+][-]
  1. var
  2.   TheDate: TDate = 40000;
  3.  
  4. procedure TForm1.DrawGrid1ButtonClick(Sender: TObject; aCol, aRow: Integer);
  5. begin
  6.   if (ACol = 1) and (ARow = 1) then begin
  7.     CalendarDialog1.Date := TheDate;
  8.     if CalendarDialog1.Execute then begin
  9.       TheDate := CalendarDialog1.Date;
  10.       DrawGrid1.EditorMode := false;
  11.     end;
  12.   end;
  13. end;
  14.  
  15. procedure TForm1.DrawGrid1DrawCell(Sender: TObject; aCol, aRow: Integer;
  16.   aRect: TRect; aState: TGridDrawState);
  17. begin
  18.   if (ACol = 1) and (ARow = 1) then
  19.     DrawGrid1.Canvas.TextOut(ARect.Left, ARect.Top, DateToStr(TheDate));
  20. end;
  21.  
  22. procedure TForm1.DrawGrid1GetEditText(Sender: TObject; ACol, ARow: Integer;
  23.   var Value: string);
  24. begin
  25.   if (ACol = 1) and (ARow = 1) then
  26.    Value := DateToStr(TheDate);
  27. end;
  28.  
  29. procedure TForm1.DrawGrid1SelectEditor(Sender: TObject; aCol, aRow: Integer;
  30.   var Editor: TWinControl);
  31. begin
  32.   if (ACol = 1) and (ARow = 1) then
  33.     Editor := DrawGrid1.EditorByStyle(cbsEllipsis);
  34. end;
Not perfect, though, because if AlwaysShowEditor is ON, the ellipsis button disappears due to my code DrawGrid1.EditorMode := false. The other idea to call DrawGrid.InvalidateCell(ACol, ARow) instead of DrawGrid1.EditorMode := false has the problem that the cell is updated only when another cell is selected. This looks as if the cell is covered by the cell editor - but I thought that the cell editor here is only the button. I must confess that I do not fully understand how the button editor works...

 

TinyPortal © 2005-2018