Recent

Author Topic: [SOLVED] stringgrid transfer selected option  (Read 2685 times)

scons

  • Full Member
  • ***
  • Posts: 141
[SOLVED] stringgrid transfer selected option
« on: March 29, 2017, 01:27:24 am »
Hi all,

I am working on parsing a stringlist into a stringrid. I have a column with a dropdown list to choose an option. This all works.
But how can I set the following:

I want the same selected option (column 5) for ALL the corresponding values in column 1 in runtime.

For example:
If column 1 has value 2, and I change column 5 to item 1 from the dropdownlist, I need all the rows that have value 2 in column 1 to change also to item 1 in column 5.

Any ideas ?
« Last Edit: March 30, 2017, 04:14:16 pm by scons »
Windows 10-64bit Lazarus 2.0.12 + FPC 3.2.0

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: stringgrid transfer selected option
« Reply #1 on: March 29, 2017, 06:03:35 am »
Something like this:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.StringGrid1PickListSelect(Sender: TObject);
  2. var
  3.   s: string;
  4.   freightNo, col1Value: integer;
  5.  
  6.   function FreightNoIsOK: boolean;
  7.   begin
  8.     freightNo:=StrToIntDef(Copy(s, 19, 1), -1);
  9.     Exit(freightNo > 0);
  10.   end;
  11.  
  12. begin
  13.   s:=StringGrid1.Cells[StringGrid1.Col, StringGrid1.Row];
  14.   col1Value:=StrToIntDef(StringGrid1.Cells[1, StringGrid1.Row], -1);
  15.   if (Length(s) = 19) and (col1Value > -1) and FreightNoIsOK then
  16.     SyncAllMatchingColumn1s(col1Value, freightNo);
  17. end;
  18.  
  19. procedure TForm1.SyncAllMatchingColumn1s(aCol1Value, aFreightNo: integer);
  20. var
  21.   r: integer;
  22.   s: string;
  23. begin
  24.   s:=Format('Freight transport %d',[aFreightNo]);
  25.   for r:=1 to StringGrid1.RowCount-1 do begin
  26.     if (StrToIntDef(StringGrid1.Cells[1, r], -1) = aCol1Value) then
  27.       StringGrid1.Cells[5, r]:=s;
  28.   end;
  29. end;    

scons

  • Full Member
  • ***
  • Posts: 141
Re: stringgrid transfer selected option
« Reply #2 on: March 30, 2017, 04:14:00 pm »
Fantastic, works like a charm !!

Thanks Mr howardpc
Windows 10-64bit Lazarus 2.0.12 + FPC 3.2.0

 

TinyPortal © 2005-2018