Recent

Author Topic: [Solved] DBLookupCombobox & DBGrid  (Read 411 times)

folkeu08

  • Jr. Member
  • **
  • Posts: 85
[Solved] DBLookupCombobox & DBGrid
« on: September 01, 2022, 03:25:44 pm »
Hi All,

I have 2 SQLite tables managed by 2 SQLQuery, one "Year" and the other "Outgoing Mail".
In the DBLookupComboBox appears the values ​​of the "Year" table.
In the grid, I'm looking to show only the rows that are identical to the 'id_year' field present in each table. They are joined by a ForeignKey.
is indeed a DBLookupComboBox that I have to use for this selection of the year or another component (DBCombobox, ...).
In SQL, do I need to do a table join?
I add the source too.
thanks
Fokeu
« Last Edit: September 02, 2022, 10:43:23 am by folkeu08 »

Zvoni

  • Hero Member
  • *****
  • Posts: 1493
Re: DBLookupCombobox & DBGrid
« Reply #1 on: September 01, 2022, 05:11:10 pm »
You have to add a Filter in your SQL
Aircode!
Code: Pascal  [Select][+][-]
  1. SQLDBGrid.SQL.Text:='SELECT * FROM DBGridTable WHERE Year=:YearParam';
  2. SQLDBGrid.ParamByName('YearParam').AsInteger:=DBLookupCombo.text.ToInteger;
  3. SQLDBGrid.Open;
  4. //Refresh DBGrid
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

folkeu08

  • Jr. Member
  • **
  • Posts: 85
Re: DBLookupCombobox & DBGrid
« Reply #2 on: September 02, 2022, 09:41:20 am »
Hi Zvoni,

Thanks for this help.
I applied the changes to my source and I got a compile error which makes sense.
I have an "illegal qualifier" error for this part: AnneeCourrierSortant_DBLookupComboBox.Text.toInteger -> courrierframe_unit.pas(161,129) Error: Illegal qualifier
Text and integer are incompatible.
In a property, no way to apply 'strtoint'.
I re-added the edited source.
I continue this research in this direction.
Folkeu
« Last Edit: September 02, 2022, 10:22:47 am by folkeu08 »

folkeu08

  • Jr. Member
  • **
  • Posts: 85
Re: DBLookupCombobox & DBGrid
« Reply #3 on: September 02, 2022, 10:07:25 am »
Hi,

We can replace the "Text.ToInteger" by the "KeyValue" because when I select another year, I get the KeyValue from the integer value of the year of the "id_year" field.
Now, it is necessary to make this value coincide with that of the grid to display only the selected one.
I use a Showmessage (IntToStr(AnneeCourrierSortant_DBLookupComboBox.KeyValue) to verifie the value.
I advance !
Folkeu

folkeu08

  • Jr. Member
  • **
  • Posts: 85
Re: DBLookupCombobox & DBGrid
« Reply #4 on: September 02, 2022, 10:42:59 am »
Hi all,

I found !
The source code is attached for the correct selection when opening the file.
All you have to do is add some code to the OnChange of the DBLookupComboBox.
thanks
Folkeu

Zvoni

  • Hero Member
  • *****
  • Posts: 1493
Re: DBLookupCombobox & DBGrid
« Reply #5 on: September 02, 2022, 12:18:53 pm »
Hi Zvoni,

Thanks for this help.
I applied the changes to my source and I got a compile error which makes sense.
I have an "illegal qualifier" error for this part: AnneeCourrierSortant_DBLookupComboBox.Text.toInteger -> courrierframe_unit.pas(161,129) Error: Illegal qualifier
Text and integer are incompatible.
In a property, no way to apply 'strtoint'.
I re-added the edited source.
I continue this research in this direction.
Folkeu
Arggh!
I always forget that for Type-Helpers you have to include the Unit and/or have to set a Modeswitch(?)
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

folkeu08

  • Jr. Member
  • **
  • Posts: 85
Re: [Solved] DBLookupCombobox & DBGrid
« Reply #6 on: September 02, 2022, 01:49:16 pm »
Hi Zvoni,
it does not matter because you allowed me to go to another technique that I knew how to exploit.
Thanks
Folkeu

 

TinyPortal © 2005-2018