Recent

Author Topic: Only 1 ComboBox in only 1 specified cell of StringGrid  (Read 9593 times)

asdf

  • Sr. Member
  • ****
  • Posts: 310
Only 1 ComboBox in only 1 specified cell of StringGrid
« on: December 21, 2010, 03:24:19 pm »
I got this from internet.
.
.
.

How can we apply to have only 1 ComboBox in only StringGrid2.Cells[1,1] ?                                      
« Last Edit: December 22, 2010, 09:20:27 am by asdf »
Lazarus 1.2.4 / Win 32 / THAILAND

cpalx

  • Hero Member
  • *****
  • Posts: 754
Re: Only 1 ComboBox in only 1 specified cell of StringGrid
« Reply #1 on: December 21, 2010, 04:31:18 pm »
change

if ACol in [1] then
...

by

if (ACol =1)and(Arow=1) then
...

asdf

  • Sr. Member
  • ****
  • Posts: 310
Re: Only 1 ComboBox in only 1 specified cell of StringGrid
« Reply #2 on: December 21, 2010, 04:45:25 pm »
Thank you so much.
And I found another example ...


1. Very nice but it still stood silent. What should I do more after putting StringGrid1 on Form1 ?
2. And how can we apply to have only 1 ComboBox in only StringGrid1.Cells[1,1] ?  
« Last Edit: December 22, 2010, 09:19:40 am by asdf »
Lazarus 1.2.4 / Win 32 / THAILAND

cpalx

  • Hero Member
  • *****
  • Posts: 754
Re: Only 1 ComboBox in only 1 specified cell of StringGrid
« Reply #3 on: December 21, 2010, 05:41:39 pm »
Acol te dice la columna y Arow la fila ...

Hydexon

  • Full Member
  • ***
  • Posts: 170
Re: Only 1 ComboBox in only 1 specified cell of StringGrid
« Reply #4 on: December 21, 2010, 05:51:47 pm »
Best alternative with the OnSelectCellEditor. avoid write the first code are you posted. i see this code in the MyDBF Studio source code by Calogiuri Enzo Antonio.

P.S: You forget the code StringGrid1.EditorByStyle(cbsPickList) if you want show the Combobox properly in the grid!
Lazarus 1.0.4 Stable - FPC 2.6.0 - gtk2 | Linux Mint 14 Nadia | GNOME Shell 3.6.2 - Awesome | Intel x86 | HP Mini 1020-LA Netbook (old)
Lazarus 2.0.2 Stable - FPC 3.0.2 - Windows | Lenovo IdeaPad Y

asdf

  • Sr. Member
  • ****
  • Posts: 310
Re: Only 1 ComboBox in only 1 specified cell of StringGrid
« Reply #5 on: December 22, 2010, 10:01:07 am »
Thank you, now I headed for using cbsPickList.

begin
  stringgrid1.Columns.Add;
  stringgrid1.Columns[0].ButtonStyle:=cbspicklist;
  stringgrid1.Options:=stringgrid1.Options+[goediting];
end;       

The same old question please, how can I specify only one cell in StringGrid1 ( for example: StringGrid1.Cells[1,3] ) to have the cbsPickList ?
Lazarus 1.2.4 / Win 32 / THAILAND

jesusr

  • Sr. Member
  • ****
  • Posts: 496
Re: Only 1 ComboBox in only 1 specified cell of StringGrid
« Reply #6 on: December 23, 2010, 10:17:17 pm »
if you have specified column 0 (that would be column 1 if you have a fixed col) as cbsPickList but yet you want only editor on grid.cells[1,3] create an OnSelectEditor event handler for this grid, and specify that Editor will be nil for all rows except 3, for example:

Code: [Select]
  if (aCol=1) and (aRow<>3) then
    Editor := nil;

asdf

  • Sr. Member
  • ****
  • Posts: 310
Re: Only 1 ComboBox in only 1 specified cell of StringGrid
« Reply #7 on: December 25, 2010, 09:39:23 am »
procedure TForm1.FormCreate(Sender: TObject);
begin
stringgrid1.Columns.Add;
stringgrid1.Columns.Add;
stringgrid1.Columns[0].ButtonStyle:=cbspicklist;
stringgrid1.Options:=stringgrid1.Options+[goediting];
end;

procedure TForm1.StringGrid1SelectCell(Sender: TObject; aCol, aRow: Integer;
  var CanSelect: Boolean);
begin
  if (aCol=1) and (aRow<>3) then begin
    CanSelect := true;
  end;
end;

procedure TForm1.StringGrid1SelectEditor(Sender: TObject; aCol, aRow: Integer;
  var Editor: TWinControl);
begin
  if (aCol=1) and (aRow<>3) then Editor := nil;
end;                 

Column 0, could not be edited in row 1,2 and 4.
How can stringgrid1.Options:=stringgrid1.Options+[goediting]; work on such cells ?

But stringgrid1.Options:=stringgrid1.Options+[goediting]; worked on column 1.
« Last Edit: December 25, 2010, 09:46:05 am by asdf »
Lazarus 1.2.4 / Win 32 / THAILAND

 

TinyPortal © 2005-2018