Recent

Author Topic: Selecting a certain image for the TDBLookupCombobox  (Read 1361 times)

madref

  • Hero Member
  • *****
  • Posts: 823
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Selecting a certain image for the TDBLookupCombobox
« on: February 02, 2020, 03:33:11 pm »
i want to use a specific image in front of my TDBLookUpComboBox.
With this code I can select images from my imagelist depending on the index.
Code: Pascal  [Select][+][-]
  1. procedure TForm_Wedstrijd_Overzicht.CB_DivisieDrawItem(Control: TWinControl;  
  2.   Index: Integer; ARect: TRect; State: TOwnerDrawState);
  3. var b, d: integer;
  4.      s: string;
  5. begin
  6.   CB_Divisie.Canvas.FillRect(ARect);                                      
  7.   CB_Divisie.Canvas.TextRect(ARect, 25, ARect.Top, CB_Divisie.Items[Index]);  
  8.   Form_RefereeMain.ImageList_Buttons.Draw(CB_Divisie.Canvas, ARect.Left + 1, ARect.Top + 1, Index);
  9. end;
CB_Divisie is declared as a TDBLookupCombobox.
This is filed with the next query:
Code: MySQL  [Select][+][-]
  1. SELECT Divisie_ID, Divisie_Tekst, Divisie_Volgorde, Divisie_Gebruiken, Divisie_Bond
  2. FROM tbl_Divisie INNER JOIN tbl_Wedstrijden ON
  3. tbl_Wedstrijden.Wed_Divisie = tbl_Divisie.Divisie_ID
  4. WHERE ((Wed_Seizoen_ID = :Wed_Seizoen_ID) OR :Wed_Seizoen_ID = 0)
  5. GROUP BY Divisie_ID
  6. UNION SELECT Divisie_ID, Divisie_Tekst, Divisie_Volgorde, Divisie_Gebruiken, Divisie_Bond›
  7. FROM tbl_Divisie  
  8. WHERE Divisie_ID = 1
  9. GROUP BY Divisie_ID
  10. ORDER BY Divisie_Volgorde

In the attachment you see the result

My question is how do I address the Field 'Divisie_Bond' so I can use that to get the correct image in front of my selection in CB_Divisie?

This is what I came up with so far:
Code: Pascal  [Select][+][-]
  1. procedure TForm_Wedstrijd_Overzicht.CB_DivisieDrawItem(Control: TWinControl;
  2.   Index: Integer; ARect: TRect; State: TOwnerDrawState);
  3. var b, d: integer;
  4.     s: string;
  5. begin
  6.   b := 'Determine Divisie_Bond';  // <<==-- This is the million dollar question
  7.   case b of
  8.     1 : d := 115;
  9.     2 : d := 105;
  10.     3 : d := 106;
  11.     4 : d := 114
  12.   else
  13.     d := 34;
  14.   end;
  15.   CB_Divisie.Canvas.FillRect(ARect);                                    
  16.   CB_Divisie.Canvas.TextRect(ARect, 25, ARect.Top, CB_Divisie.Items[Index]);
  17.   Form_RefereeMain.ImageList_Buttons.Draw(CB_Divisie.Canvas, ARect.Left + 1, ARect.Top + 1, d);
  18. end;     // CB_DivisieDrawItem
  19.  
« Last Edit: February 04, 2020, 01:57:43 am by madref »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 2.0.6 / FPC 3.0.4
Lazarus Trunc / FPC Trunc
Mac OS X Mojave

madref

  • Hero Member
  • *****
  • Posts: 823
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Selecting a certain image for the TDBLookupCombobox
« Reply #1 on: February 03, 2020, 10:50:31 am »
Anyone?
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 2.0.6 / FPC 3.0.4
Lazarus Trunc / FPC Trunc
Mac OS X Mojave

madref

  • Hero Member
  • *****
  • Posts: 823
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Selecting a certain image for the TDBLookupCombobox
« Reply #2 on: February 05, 2020, 07:56:26 am »
Since no one seems to know a good answer to my question I cam up with a solution myself.
Not ideally, but it's crude and it works.You can copy an entire Imagelist to another Imagelist with
Code: Pascal  [Select][+][-]
  1. ImageList_1.AddImages(ImageList_2);
So I created 4 Imagelist's to hold each 1 image and with a case-statement I managed to do what I wanted.

So the final code looks like this
Code: Pascal  [Select][+][-]
  1. procedure TForm_Wedstrijd_Overzicht.Verander_Disvisie_ImageList;
  2. var tqd: TSQLQuery;
  3.     b: integer;
  4. begin
  5.   ImageList_Divisie.Clear;
  6.   tqd := TSQLQuery.Create(self);
  7.   tqd.DataBase := Form_RefereeMain.Connect_RefereeDB;
  8.   tqd.SQL.Clear;
  9.   tqd.SQL.Text := 'SELECT Divisie_ID, Divisie_Volgorde, Divisie_Gebruiken, Divisie_Bond ' +
  10.                   'FROM tbl_Divisie INNER JOIN tbl_Wedstrijden ON ' +
  11.                   'tbl_Wedstrijden.Wed_Divisie = tbl_Divisie.Divisie_ID ' +
  12.                   'WHERE ((Wed_Seizoen_ID = :Wed_Seizoen_ID) OR :Wed_Seizoen_ID = 0) ' +
  13.                   'GROUP BY Divisie_ID ' +
  14.                   'UNION SELECT Divisie_ID, Divisie_Volgorde, Divisie_Gebruiken, Divisie_Bond ' +
  15.                   'FROM tbl_Divisie  ' +
  16.                   'WHERE Divisie_ID = 1 ' +
  17.                   'GROUP BY Divisie_ID ' +
  18.                   'ORDER BY Divisie_Volgorde;';
  19.   tqd.Params.ParamByName('Wed_Seizoen_ID').AsInteger := CB_Seizoen.KeyValue;
  20.   tqd.Open;
  21.   tqd.First;
  22.   while not tqd.Eof do
  23.   begin
  24.     b := tqd.FieldByName('Divisie_Bond').AsInteger;
  25.     case b of
  26.         1 : ImageList_Divisie.AddImages(ImageList_IIHF);
  27.         2 : ImageList_Divisie.AddImages(ImageList_NIJB);
  28.         3 : ImageList_Divisie.AddImages(ImageList_BeNe);
  29.         4 : ImageList_Divisie.AddImages(ImageList_RHC);
  30.     else
  31.       ImageList_Divisie.AddImages(ImageList_Niks);
  32.     end;
  33.     tqd.Next;
  34.   end;
  35.   // Query uit het geheugen halen.
  36.   tqd.Active := False;
  37.   tqd.Free;
  38. end;     // Verander_Disvisie_ImageList

and then in

Code: Pascal  [Select][+][-]
  1. procedure TForm_Wedstrijd_Overzicht.CB_DivisieDrawItem(Control: TWinControl;
  2.   Index: Integer; ARect: TRect; State: TOwnerDrawState);
  3. begin
  4.   CB_Divisie.Canvas.FillRect(ARect);
  5.   CB_Divisie.Canvas.TextRect(ARect, 25, ARect.Top, CB_Divisie.Items[Index]);
  6.   ImageList_Divisie.Draw(CB_Divisie.Canvas, ARect.Left + 1, ARect.Top + 1, Index);
  7. end;     // CB_DivisieDrawItem
  8.  
« Last Edit: February 05, 2020, 07:58:06 am by madref »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 2.0.6 / FPC 3.0.4
Lazarus Trunc / FPC Trunc
Mac OS X Mojave

wp

  • Hero Member
  • *****
  • Posts: 7620
Re: Selecting a certain image for the TDBLookupCombobox
« Reply #3 on: February 05, 2020, 06:44:13 pm »
Maybe I don't understand the problem. But why do you have to use different image lists at all? Can't you merge all images into the same image list?
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

madref

  • Hero Member
  • *****
  • Posts: 823
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Selecting a certain image for the TDBLookupCombobox
« Reply #4 on: February 06, 2020, 06:16:51 pm »
No because the ImageList that I choose from is a list with 116 images.
In my initial post I tried to do it in the CB_DivisieDrawItem
-procedure but I could not determine B.
So I know how to copy an complete imagelist to another. SO I made 5 imageless with each one image in it.
« Last Edit: February 06, 2020, 06:25:46 pm by madref »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 2.0.6 / FPC 3.0.4
Lazarus Trunc / FPC Trunc
Mac OS X Mojave

 

TinyPortal © 2005-2018