delphi中button与combobox的连接

来源:百度知道 编辑:UC知道 时间:2024/05/23 02:25:54
我的目的是要在combobox里写文字,点击BUTTON后,得到相应的回应。
小弟我是个初学delphi,详细讲解。各位大侠谢谢。
BUTTON链接combobox中ltems中的数值。就是不要让它默认出现combobox的名字。
急!我在线等候。

在form 的oncreate事件写代码:
procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBox1.ItemIndex := 0;//默认选中Item中的第一个
combobox1.Items.Add(ADOTable1.FieldByName('username').AsString);
ComboBox1.Style := csDropDownList;//表示只能选中下拉的内容,不能用手输入
end;
//注:username为数据库表里面的字段名

很抱歉,你描述的不是很清楚,请你描述清楚后再问。

你可以试试这个

procedure TForm1.btn1Click(Sender: TObject);
begin
ShowMessage(cbb1.Text);
end;

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
ComboBox1: TComboBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedur