COMBOBOX删除记录求解(30分)

  • 主题发起人 topdelphi
  • 开始时间
T

topdelphi

Unregistered / Unconfirmed
GUEST, unregistred user!
两个选择框里同时读取数据库的同一个字段记录,记录如下:
COMBOX1 COMBOX2
1 1
2 2
。。。。。 。。。。
如何做到例如在COMBOX1里选择1后,COMBOX2就删除1在COMBOX2的记录,但不是删除数据库的
记录,只是删除在COMBOX里面的, 相反,在COMBOX2里选择1后,COMBOX1就删除1在COMBOX2的记录,代码如下
但只是写出一小处地方,而且也要另一个COMBOX选择之后,才可删除的.请教这个功能如何写啊。

procedure TForm1.Button1Click(Sender: TObject);
begin
form2.Show;
ado.First;
while not ado.Eof do begin
form2.ComboBox1.Items.Add(ado.Fields[2].AsString);
form2.ComboBox2.Items.Add(ado.Fields[2].AsString);
ado.Next;
end;
ado.First;
end;

procedure TForm2.ComboBox1Select(Sender: TObject);
var
i:integer;
begin
for i:=0 to combobox1.Items.Count -1 do begin
if combobox1.ItemIndex =i then
begin
combobox2.DeleteSelected
end;
end;
end;


 
执行这个可以实现:
combobox2.items.delete[combobox1.itemindex];
combobox1.items.delete[combobox2.itemindex];
如果不选择时要恢复已删除的ITEM,则执行之前应重新写入COMBOBOX。
 
combobox2.items.delete[ComboBox2.items.IndexOf(combobox1.text)];
 
//选中Combobox1里的项目删除Combobox2里相应项目
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
ComboBox2.Items.Delete(ComboBox2.Items.IndexOf(ComboBox1.Text));

end;
 
//选中Combobox1里的项目删除Combobox2里相应项目
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
ComboBox2.Items.Delete(ComboBox2.Items.IndexOf(ComboBox1.Text));

end;
 
但是我想请教如果用户之前选择了,但最的没有选择到,我也还是要将这些删除的数据显示
出来,我的方法每次打开这个窗体都将数据库的数据读出来,请教还有没有更好的方法啊。
而且我上面的问题修改如下,没有测试过,请问我有没有写错啊。

procedure TForm2.ComboBox1Select(Sender: TObject);
var
i:integer;
begin
for i:=0 to combobox1.Items.Count -1 do begin
if combobox1.ItemIndex =i then
begin
执行这个可以实现:
combobox2.items.delete[combobox1.itemindex];
combobox1.items.delete[combobox2.itemindex];
end;
end;
end;
 
顶部