Recent

Author Topic: DBLookUpComboBox shows blank  (Read 9094 times)

mizar

  • New Member
  • *
  • Posts: 44
DBLookUpComboBox shows blank
« on: December 12, 2015, 01:19:17 pm »
I'm using a DBLookUpComboBox the usual way, i.e. to pick up a value from the SourceList DS and setting the corresponding field in the DataSource DS.

The trouble is that the form comes up with the component blank.  I want it to show the current post field. As soon as I edit the DataSource DS everything is displayed correctly, but not when the form shows up.
Using a simpler DBComboBox the underlying value is always shown correctly, but I lose the data-awareness of the SourceList.

Any help appreciated. TIA.

balazsszekely

  • Guest
Re: DBLookUpComboBox shows blank
« Reply #1 on: December 12, 2015, 04:11:18 pm »
Hi mizar,

Something similar(see screenshots)?: http://bugs.freepascal.org/view.php?id=26356

mizar

  • New Member
  • *
  • Posts: 44
Re: DBLookUpComboBox shows blank
« Reply #2 on: December 12, 2015, 04:31:11 pm »
First of all thank you for your reply.

No, not the same issue.

If I click on the embedded button I can see correctly all the items in SourceList.
When the form shows up, the current record in DataSource has the Key field set at a valid value but the combo is blank. If I, as an example, move to the next record the combo shows the correct value and if I move back to the previous record, the combo shows the value as well. It doesn't work only at the beginning...

balazsszekely

  • Guest
Re: DBLookUpComboBox shows blank
« Reply #3 on: December 12, 2015, 06:48:48 pm »
Quote
@mizar
f I, as an example, move to the next record the combo shows the correct value and if I move back to the previous record, the combo shows the value as well. It doesn't work only at the beginning...

This is very strange indeed! Then, you should move to the next record, then back to the previous one programmatically
  SQLQuery1.Next;
  SQLQuery1.Prior;
If this works, you can even disable the visual controls to prevent the flickering:
Quote
  SQLQuery1.DisableControls
  try
    SQLQuery1.Next;
    SQLQuery1.Prior;
  finally
    SQLQuery1.EnableControls;
  end;

LuizAmérico

  • Sr. Member
  • ****
  • Posts: 457
Re: DBLookUpComboBox shows blank
« Reply #4 on: December 12, 2015, 07:02:02 pm »
Can you post a sample project?

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1875
Re: DBLookUpComboBox shows blank
« Reply #5 on: December 12, 2015, 10:03:05 pm »
Had the same problem ... very hard to solve.

You can use two methods:

1: RefreshLookupList of lookupfield
2: DataSet.Resync([]);

I use both !

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: DBLookUpComboBox shows blank
« Reply #6 on: December 13, 2015, 09:29:19 am »
Quote
I want it to show the current post field. As soon as I edit the DataSource DS everything is displayed correctly, but not when the form shows up.
In lazarus first you have to open the actual datasource and than the listsource.
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

mizar

  • New Member
  • *
  • Posts: 44
Re: DBLookUpComboBox shows blank
« Reply #7 on: December 13, 2015, 04:58:31 pm »
Thank you all,

I'll post a sample project reproducing the issue as soon as possible, in the meantime:

- reading http://wiki.freepascal.org/dblookupcombobox:
Quote

// The ComboBox should now be populated, however intially no text is displayed
// So right now there is no relationship between the selected record in the dataset
// and the contents of the ComboBox

and proposes to set KeyValue property:
Code: Pascal  [Select][+][-]
  1. cboLookup.KeyValue := dsetSource.FieldByName(FKeyField).AsVariant;


Well, to avoid any streaming system related problem, I dropped a Button on the form and in the OnClick event I tried:
Code: Pascal  [Select][+][-]
  1. cboLookup.KeyValue := dsetSource.FieldByName(FKeyField).AsVariant;

and it works ! (the combo shows the value)

Then tried:

Code: Pascal  [Select][+][-]
  1. DataSet.Resync([]);

Code: Pascal  [Select][+][-]
  1. DataSet.Refresh;

Code: Pascal  [Select][+][-]
  1. DataSet.Next;
  2. DataSet.Prior;

and they worked too;

Instead:
Code: Pascal  [Select][+][-]
  1. DBLookUPCombo.Refresh;
Code: Pascal  [Select][+][-]
  1. ListSource.Refresh;
Code: Pascal  [Select][+][-]
  1. ListSource.Resync([]);
Code: Pascal  [Select][+][-]
  1. ListSource.Close;
  2. ListSource.Open;
Code: Pascal  [Select][+][-]
  1. DataSet.FieldByName(...).RefreshLookupList
Code: Pascal  [Select][+][-]
  1. ListSource.FieldByName(...).RefreshLookupList

none of them worked.

Now I have to decide in which form's event I have to put the code.

Btw, RXDBLookUpComboBox works out of the box (but it's not so uniform to the other controls).

(fpc 3.0.0, Lazarus 1.4.4 on linux x64)
« Last Edit: December 13, 2015, 05:01:53 pm by mizar »

 

TinyPortal © 2005-2018