Today, Delphi is one of the popular desktop programming tool. There are thousand even million programmer in this world using delphi as their favorit tool. This site try to collect the examples, tips and tricks of Delphi programming. We collect, test them and redistribute the collection of delphi programming for you.

Fill the Combobox Items from Dataset

Author: admin | Category: Database, Tips and Tricks

//This is how we can fill the combobox items from dataset  

unit Unit1; 

interface 

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, StdCtrls, DB, ADODB; 

type
  TForm1 = class(TForm)
    DataSource1: TDataSource;
    ADODataSet1: TADODataSet;
    ComboBox1: TComboBox;
    DBGrid1: TDBGrid;
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end; 

var
  Form1: TForm1; 

implementation 

{$R *.dfm} 

procedure TForm1.FormShow(Sender: TObject);
var
  i:integer;
begin
  i:=1;
  while i <= ADODataSet1.RecordCount do
  begin
     ComboBox1.Items.Add(ADODataSet1.Fieldbyname('name').AsString);
     ADODataSet1.Next;
   i:=i+1;
  end;
end; 

end. 

//In this example we use dbdemos database with Country table  

object ADODataSet1: TADODataSet
    ConnectionString =
      'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Co' +
      'mmon Files\Borland Shared\Data\dbdemos.mdb;Persist Security Info' +
      '=False'
    CommandText = 'select Name  from country'
  end

Tags: , ,