Recent

Author Topic: TDBComboBox question  (Read 1970 times)

xaver13

  • Full Member
  • ***
  • Posts: 111
TDBComboBox question
« on: November 27, 2017, 10:11:44 pm »
Hello I have problem to get checked value from TDBComboBox

I fill it
Code: Pascal  [Select][+][-]
  1.   DBCmbTyp.Items.Add('n/a');
  2.   while not Query11.EOF do
  3.   begin
  4.     if Query11['col_3'] <> null then
  5.       DBCmbTyp.Items.Add(Query11['col_3']);
  6.       Query11.Next;
  7.   end;

But how to get which value user selected ?

I can compile something as

Code: Pascal  [Select][+][-]
  1. DBCmbTyp.Text

I need to use it in a code
Code: Pascal  [Select][+][-]
  1. Query1.SQL.Text := 'Select * From wallet where col_3 = ' + DBCmbTyp.Text;
  2.  

but it works not.

Please do you know simple and clever solution?

Thank you very much for help.
--
Jiri Cvrk

PatBayford

  • Full Member
  • ***
  • Posts: 125
Re: TDBComboBox question
« Reply #1 on: November 27, 2017, 11:37:48 pm »
DBCmbTyp.Items holds the text values of the entries.
DBCmbTyp.ItemIndex holds the index of the selected item in the list, assuming you do not allow multi-select.
So, the selected entry from  the list is given by DBCmbTyp.Items[DBCmbTyp.ItemIndex]
Lazarus 1.8.0 FPC 3.0.2 SVN 56594 Windows 10 64bit (i386-win32-win32/win64)

kapibara

  • Hero Member
  • *****
  • Posts: 610
Re: TDBComboBox question
« Reply #2 on: November 28, 2017, 12:33:24 am »
If your intention is to do master/detail (using one query or list to select a resultset with another query) then you may have a look at the tutorial below. There is no need to set the SQL.Text manually, it is automatic if you learn how to do it:

http://wiki.freepascal.org/MasterDetail
« Last Edit: November 28, 2017, 12:41:58 am by kapibara »
Lazarus trunk / fpc 3.2.2 / Kubuntu 22.04 - 64 bit

 

TinyPortal © 2005-2018