Recent

Author Topic: LCL: db-aware combobox that scrolls the dataset  (Read 546 times)

edgen

  • Newbie
  • Posts: 4
LCL: db-aware combobox that scrolls the dataset
« on: April 16, 2019, 02:15:26 pm »
Hi!

I need a component that allows user to scroll the dataset like DBGrid does. I need this behavior to change content of the detail grid. It should use small area of the window, so I think it will be great if it's a dropdown box. Could anyone advise such existing component or I should write a new one?

Thanks!

madref

  • Hero Member
  • *****
  • Posts: 679
  • ..... A day not Laughed is a day not Lived !!
    • Nursing With Humour
Re: LCL: db-aware combobox that scrolls the dataset
« Reply #1 on: April 17, 2019, 07:12:05 am »
Something like this?
Code: Pascal  [Select]
  1. var
  2.     CB_Seizoen: TDBLookupComboBox;
  3.     DS_Straffen: TDataSource;
  4.     DS_Seizoen: TDataSource;
  5.     TQ_Straffen: TSQLQuery;
  6.     TQ_Seizoen: TSQLQuery;
  7.     // These are alle present on your form.
  8.  
  9. procedure TForm_RapportStraffenOverzicht.FormShow(Sender: TObject);
  10. var cSQL: string;
  11. begin
  12.   cSQL := 'SELECT Seizoen AS Sei_ID, tbl_Seizoenen.Sei_Periode, Sei_Letter FROM qry_Overzicht_Evaluaties ' +
  13.           'INNER JOIN tbl_Seizoenen ON tbl_Seizoenen.SEI_ID = qry_Overzicht_Evaluaties.Seizoen ' +
  14.           'GROUP BY Seizoen ' +
  15.           'UNION SELECT 0, "(All)" As Sei_Periode, "ZZ" ' +
  16.           'FROM tbl_Seizoenen ' +
  17.           'ORDER BY Sei_Letter DESC;';
  18.   TQ_Seizoen.DataBase := Form_RefereeMain.Connect_RefereeDB;
  19.   TQ_Seizoen.SQL.Text := cSQL;
  20.   TQ_Seizoen.Active := True;
  21.   // setup TDBLookupCombobox
  22.   CB_Seizoen.ScrollListDataset := True;
  23.   CB_Seizoen.ListSource := DS_Seizoen;
  24.   CB_Seizoen.ListField := 'SEI_Periode';
  25.   CB_Seizoen.KeyField := 'SEI_ID';
  26.   CB_Seizoen.KeyValue := Form_RefereeMain.BepaalHuidigSeizoen; // Spring naar de actieve seizoen
  27.   cSQL := 'SELECT RS_ID, RS_Wed_ID, RS_Naam AS Name, RS_NIJB_ID AS [Union No.], RS_Funktie AS Function, ' +
  28.           'CASE WHEN RS_Straf=1 THEN "x" ELSE NULL END AS GMP, ' +
  29.           'CASE WHEN RS_Straf=2 THEN "x" ELSE NULL END AS MP, ' +
  30.           'CASE WHEN RS_Straf=3 THEN "x" ELSE NULL END AS Inc, ' +
  31.           'Team, StrFTime(' + SingleQuotedStr ('%d-%m-%Y') + ', Datum) AS Date, ' +
  32.           'StrFTime(' + SingleQuotedStr ('%H:%M') + ', Tijd) AS Time, ' +
  33.           'RS_Team, Datum, Tijd, Seizoen, qry_Teams.Divisie, ' +
  34.           'StrFTime(' + SingleQuotedStr ('%d-%m-%Y') + ', RS_Datum_Verstuurd) AS [Report Send] ' +
  35.           'FROM tbl_Rapport_Straffen ' +
  36.           'INNER JOIN qry_Overzicht_Wedstrijden ON qry_Overzicht_Wedstrijden.Wed_ID = tbl_Rapport_Straffen.RS_Wed_ID ' +
  37.           'INNER JOIN qry_Teams on qry_Teams.Team_ID = tbl_Rapport_Straffen.RS_Team ' +
  38.           'WHERE ((Seizoen=:Sei_ID) OR :Sei_ID=0) ' +
  39.           'ORDER BY Datum DESC, TIJD DESC, Team ASC, Name ASC';
  40.   TQ_Straffen.DataBase := Form_RefereeMain.Connect_RefereeDB;
  41.   TQ_Straffen.SQL.Text := cSQL;
  42.   TQ_Straffen.Params.ParamByName('Sei_ID').AsInteger := Form_RefereeMain.BepaalHuidigSeizoen;
  43.   TQ_Straffen.Active := True;
  44. end;
  45.  
  46. procedure TForm_RapportStraffenOverzicht.CB_SeizoenSelect(Sender: TObject);
  47. begin
  48.   if not TQ_Straffen.Active then exit;
  49.   TQ_Straffen.Active := False;
  50.   TQ_Straffen.Params.ParamByName('Sei_ID').AsInteger := CB_Seizoen.KeyValue;
  51.   TQ_Straffen.Active := True;
  52. end;     // CB_SeizoenChange
  53.  



In the attachment you see how big the combobox is.
« Last Edit: April 17, 2019, 07:25:05 am by madref »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 2.0.2 / FPC 3.0.4
Lazarus Trunc / FPC 3.0.4
Mac OS X Mojave

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1248
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

Thaddy

  • Hero Member
  • *****
  • Posts: 8664
Re: LCL: db-aware combobox that scrolls the dataset
« Reply #3 on: April 17, 2019, 11:26:46 am »
Unless the TdbComboBox has "virtual" capabilities, all that is suggested here is futile in the sense that it only applies to very small tables.
Most people that want to use threading should learn to patch their jeans first: use a needle.

edgen

  • Newbie
  • Posts: 4
Re: LCL: db-aware combobox that scrolls the dataset
« Reply #4 on: April 17, 2019, 11:55:50 am »
Something like this?

Thanks! It's good enough!
I've just missed ScrollListDataSet property.

edgen

  • Newbie
  • Posts: 4
Re: LCL: db-aware combobox that scrolls the dataset
« Reply #5 on: April 17, 2019, 12:01:42 pm »
Unless the TdbComboBox has "virtual" capabilities, all that is suggested here is futile in the sense that it only applies to very small tables.

Sure. The solution with combobox is suitable only for small datasets (or well-filtered). I think if the dataset contains more than 10-20 records it will be uncomfortable for the user to select record such way.

Thaddy

  • Hero Member
  • *****
  • Posts: 8664
Re: LCL: db-aware combobox that scrolls the dataset
« Reply #6 on: April 17, 2019, 12:36:53 pm »
Very small means less than 100-500 on most machines. 500 counts as a small table in the sense that it is easy to keep in memory.
« Last Edit: April 17, 2019, 12:39:26 pm by Thaddy »
Most people that want to use threading should learn to patch their jeans first: use a needle.

edgen

  • Newbie
  • Posts: 4
Re: LCL: db-aware combobox that scrolls the dataset
« Reply #7 on: April 17, 2019, 12:58:44 pm »
I wrote 10-20 from the UX side. Technically it's easy to keep several thousands of records in memory.
But if the lookup table contains 1000 records there are two ways (IMHO, of course):
- it's design error.
- it's complicated distionary and it needs more complex control to choose a record.