回 帖 发 新 帖 刷新版面

主题:及时显示问题请教

本人初学Delphi碰到以下问题:
 在添加一条记录后, 在combobox中不能马上显示刚刚添加那条的记录,而要退出窗体之后才能在combobox中显示刚刚添加的那条记录
程序代码是:
procedure Tman.FormShow(Sender: TObject);
begin
   Adoquery1.Open;
   while not Adoquery1.Eof do
   begin
     combobox1.Items.Add(adoquery1.Fields[0].asstring);
     Adoquery1.Next;
     end;
end;

procedure Tman.BitBtn1Click(Sender: TObject);
begin
   with Adotable1 do
   begin
   open;
   Edit;
   Append;
    if Trim(combobox1.Text)='' then
   begin
    Application.MessageBox('请输入操作员姓名','提示',0+64);
    combobox1.SetFocus;
    end
  else
  if Trim(Edit3.Text)='' then
   begin
    Application.MessageBox('请输入操作员密码','提示',0+64);
    Edit3.SetFocus;
    end
    else
    if Trim(Edit1.Text)='' then
    begin
    Application.MessageBox('请输入操作员权限','提示',0+64);
    Edit1.SetFocus;
    end
    else
    begin
    if (combobox1.Text<>'') and (Edit3.text<>'') and (Edit1.Text<>'')
    then
    begin
  if Application.MessageBox('确实要添加用户么?','提示',mb_YesNo)=ID_Yes then
    begin
    Adotable1.fieldByname('操作员姓名').AsString:=Trim(combobox1.Text);
    Adotable1.fieldByname('操作员密码').AsString:=Trim(Edit3.Text);
    Adotable1.FieldByName('操作员权限').AsString:=Trim(Edit1.Text);
  if (Adotable1.modified) then  Adotable1.post;
  combobox1.Text:='';
    Edit3.Text:='';
    Edit1.Text:='';
  end;
   end;
   end;
   end;
end;
我想应该是fromshow 事件没能及时实现.
请问delphi中还有其他的事件能实现把数据库中的记录及时的添加到combobox控件中去

回复列表 (共2个回复)

沙发

procedure Tman.FormShow(Sender: TObject);
begin
   Adoquery1.Open;
   while not Adoquery1.Eof do
   begin
     combobox1.Items.Add(adoquery1.Fields[0].asstring);
     Adoquery1.Next;
     end;
end;
这个是在formshow 事件中把adoquery1中的数据添加进combox1
所以你在之后的操作数据库是不会及时显示,我有个笨办法
建个 button,添加上面的代码,手动的刷新。

板凳

将FormShow事件改为:(添加一行)
procedure Tman.FormShow(Sender: TObject);
begin
   combobox1.Items.Clear;   
   Adoquery1.Open;
   while not Adoquery1.Eof do
   begin
     combobox1.Items.Add(adoquery1.Fields[0].asstring);
     Adoquery1.Next;
     end;
end;

  在以后的添加、删除、修改操作后,使用FormShow(Nil);调用FormShow事件即可。

  本人的网站http://axmanhz.sru.cn/  中有大量的参考资料可以使用,欢迎访问。

我来回复

您尚未登录,请登录后再回复。点此登录或注册