home *** CD-ROM | disk | FTP | other *** search
/ CD Shareware Magazine 1996 December / CD_shareware_12-96.iso / WIN / Programa / TI2956.ZIP / TI2956.ASC < prev   
Encoding:
Text File  |  1996-06-17  |  2.5 KB  |  72 lines

  1.    NUMBER  :  2956
  2.   PRODUCT  :  Delphi
  3.   VERSION  :  All
  4.        OS  :  Windows/Win32
  5.      DATE  :  June 14, 1996                           
  6.  
  7.     TITLE  :  How to Populate a TDBComboBox Or TDBListBox
  8.  
  9. Filling dblistboxs and dbcomboboxs
  10.  
  11. Most of Delphi's data aware components will  populate 
  12. themselves after they are wired up to a open dataset.  However 
  13. DbListboxs and DbComboboxs do not display this characteristic.  
  14. These two components are not for displaying your datasets, but 
  15. filling them.  Use of these components is straight forward.  
  16. When you update your table, the value of the DbListbox or 
  17. DbCombobox will be posted in the appropriate field.
  18.  
  19. Filling the DbCombobox or DbListbox the same as filling normal 
  20. comboboxs or listboxes.  The lines of text in a listbox or 
  21. combobox are really a tstring list.  The "Items" property of 
  22. the given component holds this list.  Use the "Add" method for 
  23. adding items to a tstring. If you want to use data  types other 
  24. than strings they must be converted at run time. If your list 
  25. has a blank line at the end, consider setting the 
  26. "IntegralHeight" property to True.
  27.  
  28.  
  29. Filling a DbListbox with 4 lines programmatically might look 
  30. similar to this:
  31.  
  32.      DbListbox1.items.add('line one');
  33.      DbListbox1.items.add('line two');
  34.      DbListbox1.items.add('line three');
  35.      DbListbox1.items.add('line four');
  36.  
  37. Filling a DbListbox at design time requires using the object 
  38. inspector.  By double clicking on the components "Items" 
  39. property, you can bring up the "String List Editor" and input 
  40. the desired rows.
  41.  
  42. Unfortunately, if a combobox is filled this way, there is not 
  43. default value.  Setting a DbComboboxs "text" property will 
  44. achieve this result.  (the "text" property is not available in 
  45. the object inspector, so it must be set programmatically).  
  46. Setting the default value to the first value in the 
  47. DbCombobox's list looks like this:        
  48.  
  49. DbCombobox1.text := DbCombobox1.items[0];
  50.  
  51. Often it is useful to fill a DBListBox from a dataset.  This 
  52. can be done using loop:
  53.  
  54. procedure TForm1.FormCreate(Sender: TObject);
  55. begin
  56.   with table2 do begin
  57.     open;
  58.     while not EOF do
  59.     begin
  60.       DBlistbox1.items.add(FieldByName('name').AsString); 
  61.       next;
  62.     end;
  63.   end;
  64. end;
  65.  
  66.  
  67.  
  68. DISCLAIMER: You have the right to use this technical information
  69. subject to the terms of the No-Nonsense License Statement that
  70. you received with the Borland product to which this information
  71. pertains.
  72.