Recent

Author Topic: (SOLVED) Seeing only unique values in a lookup?  (Read 3137 times)

bill0287

  • Full Member
  • ***
  • Posts: 146
(SOLVED) Seeing only unique values in a lookup?
« on: December 11, 2013, 12:15:06 am »
I have a DBF table with a column that has hundreds of rows but on 4 or five distinct value. I want to create a lookup that only returns the uniue values and not all of them. DBLookupCombobox displays everything.

How would you recommend doing this?

Edit: see comment at the end
« Last Edit: December 17, 2013, 02:57:55 am by bill0287 »

bambamns

  • Full Member
  • ***
  • Posts: 223
Re: Seeing only unique values in a lookup?
« Reply #1 on: December 11, 2013, 05:26:51 am »
Did yo tried with TDBF.Locate ?
Lazarus 1.8.4 + FPC 2.6.4 x86 (rebuild) and Lazarus 2.0, Windows 7 x64, unless otherwise specified

bill0287

  • Full Member
  • ***
  • Posts: 146
Re: Seeing only unique values in a lookup?
« Reply #2 on: December 11, 2013, 06:24:49 am »
I am trying to use something like DBLookupComboBox on a field so that I can choose a filter value.

For example, if the field were:

COLOR
White
Black
White
Red
White
White
White

I would want the LookupCombo to only return these as choices:

White
Black
Red

bambamns

  • Full Member
  • ***
  • Posts: 223
Re: Seeing only unique values in a lookup?
« Reply #3 on: December 12, 2013, 02:53:52 am »
AFAIK you need an SQL to do it and to achieve it you have to access to DBF with TODBCConnection and TSQLQuery.
If you are using Windows , you can use Microsoft dBase driver or Microsoft Access dBase driver to access to DBF.
« Last Edit: December 12, 2013, 03:13:18 am by bambamns »
Lazarus 1.8.4 + FPC 2.6.4 x86 (rebuild) and Lazarus 2.0, Windows 7 x64, unless otherwise specified

bill0287

  • Full Member
  • ***
  • Posts: 146
Re: Seeing only unique values in a lookup?
« Reply #4 on: December 17, 2013, 02:57:25 am »
FWIW, I found this code that will solve the problem. It is probably only good for smaller datasets but it works nicely in the OnEnter event of the combobox:

Code: [Select]
var
SL: TStringList;
begin
  SL := TStringList.Create;
  SL.Sorted := True; // must be set, otherwise next line has no effect
  SL.Duplicates := dupIgnore; // don't accept duplicates
  SL.AddStrings(DBLookupComboBox1.Items);
  DBLookupComboBox1.Items.Assign(SL);
  SL.Free;
end;

 

TinyPortal © 2005-2018