Recent

Author Topic: on dbcombobox1 change update dbcombobox2  (Read 2893 times)

Danyfirex

  • New Member
  • *
  • Posts: 13
on dbcombobox1 change update dbcombobox2
« on: July 01, 2015, 07:47:17 pm »
hi mate. it's me again. is there a way (I mean using dbcombobox properties to do that). I mean this.

I have my database.db

has many tables some table field is a reference to another table field.

example tables:

Table1->Person
ID|Name|idCountry|idCity|idTown

table2->Country
ID|country_name

table3->City
ID|city_name

table3->town
ID|town_name

is there some properties that let me fill the combo with all the field that is refered to.


Combocountry1=if i choose some contry combocity get all cities that are refere to that country.

combocity2 if i choose a city my combotown3 get all town that are refere to that city.

combotown3 here make some similar but with  another things.


I know this can be done using my dataset but I asking if exist a fast way with the dbcombobox properties to do that more flexible,fast,practical.


Saludos


taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: on dbcombobox1 change update dbcombobox2
« Reply #1 on: July 01, 2015, 07:51:05 pm »
Use DBLookupComboBox instead.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Danyfirex

  • New Member
  • *
  • Posts: 13
Re: on dbcombobox1 change update dbcombobox2
« Reply #2 on: July 01, 2015, 08:26:52 pm »
mate can you provide me scheme how to se the propierties. I'm trying with DBLookupComboBox but I can't figure me how to do it.

Saludos

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: on dbcombobox1 change update dbcombobox2
« Reply #3 on: July 01, 2015, 08:42:58 pm »
use a query that returns all the records from the country table and a second query that returns all records of the person table and link them to datasources lets name them QryPerson for the person query DSPerson for the person datasource and QryCountry, DSCountry for the country controls respectively. DBLookupCombobox has 2 groups main groups of properties 1) the data to be changed when the combobox is used to select a value and 2) the query that provides the values you can choose from.
in the first group are the properties Datasource, Datafield which must be linked to the DSPerson and IDCountry field and in the second group are the properties Listsource linked to dsCountry, listField must be linked to the Country_name field and KeyField that must be linked to the DSCountry.ID field.
After that if you use the default property values every time you select a country in the dblookupcombobox it will change the active record's idcountry field value the new one selected. All filling and setting is taken care for you internally.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Danyfirex

  • New Member
  • *
  • Posts: 13
Re: on dbcombobox1 change update dbcombobox2
« Reply #4 on: July 01, 2015, 10:30:28 pm »
Thank you very much mate that's help me so much. so I have another problem. The code work well. but For example:

when I select my contry in my dblookupcomboboxContry my dblookupcomboboxCity get update so. I want to show just the cities from that contry but it show me all my cities. show I work with query on the change event. o could be done with the properties.

Saludos

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: on dbcombobox1 change update dbcombobox2
« Reply #5 on: July 01, 2015, 10:40:03 pm »
It can be done with properties yes. You make sure the city query includes a parameterize where statement. Something along the lines of
Code: [Select]
QryCity.SelectSql.text := 'Select * from City where IdCountry = :ID' I'm writing id as the name of the id field in the country query, it must much what ever the country query uses for the ID field name exactly, then you set the qryCity.DataSource property to the dsCountry. for more details visit http://wiki.freepascal.org/MasterDetail
« Last Edit: July 01, 2015, 10:54:21 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Danyfirex

  • New Member
  • *
  • Posts: 13
Re: on dbcombobox1 change update dbcombobox2
« Reply #6 on: July 01, 2015, 10:43:01 pm »
I solved that part by this way.

on the event change make a new query on the City refered to my contry idContry value.

Code: [Select]
QryCity.Close;
QryCity.SQL.Text:='SELECT * FROM City where idCoutry='''+inttostr(LookDBCountry.KeyValue)+'''';
QryCity.Open;   

So if there is another way let me know it.

¿taazz by properties would be? Sorry if I ask too much. so there is not good reference using that control.

Thank you very much Mr. taazz.

I'll look the link. Thank you. I'll come back with the result.

Saludos
« Last Edit: July 01, 2015, 11:09:31 pm by Danyfirex »

 

TinyPortal © 2005-2018