编程论坛
注册
登录
编程论坛
→
Delphi论坛
[求助]数据加入求助
avon4563
发布于 2006-04-13 09:16, 586 次点击
窗体中,一个ListBox,一个ComboBox.我想实现双击ListBox里面某一项时,ComboBox中就添加一项,假如ComboBox里面有相同项时,该加入动作无效.
各位大虾帮眼看看,帮帮忙啊.........
7 回复
#2
avon4563
2006-04-13 09:26
我之前是这样做的,你们同时也帮我看看错哪了
if (ListBox1.Items.Strings[ListBox1.ItemIndex]=ComboBox1.Items.Strings[ComboBox1.ItemIndex]) then
exit;
ComboBox1.Items.Delete(ComboBox1.Items.Add(ComboBox1.ItemIndex));
ComboBox1.Items.Add(ListBox1.Items.Strings[ListBox1.ItemIndex]);
ComboBox1.ItemIndex := ComboBox1.Items.Count - 1;
#3
avon4563
2006-04-13 09:30
上面我发多了一行:第三行
if (ListBox1.Items.Strings[ListBox1.ItemIndex]=ComboBox1.Items.Strings[ComboBox1.ItemIndex]) then
exit;
ComboBox1.Items.Add(ListBox1.Items.Strings[ListBox1.ItemIndex]);
ComboBox1.ItemIndex := ComboBox1.Items.Count - 1;
#4
avon4563
2006-04-15 08:44
有没有人帮我看看问题出在哪里啊,今天星期六,应该有人回应一下了吧.
#5
yuxue1985
2006-04-15 10:38
你是用的什么触发事件?
我看也没有错啊
先判断然后添加
你把你的错误说明白
#6
hanppern
2006-04-16 09:56
if ComboBox1.Items.Indexof(ListBox1.Items.Strings[ListBox1.ItemIndex])=-1 then
ComboBox1.Items.add(ListBox1.Items.Strings[ListBox1.ItemIndex]);
#7
ysp_1984
2006-04-16 13:42
procedure TForm1.ListBox1DblClick(Sender: TObject);
var
temp:string;
begin
temp:=listbox1.Items[listbox1.itemindex];
if combobox1.Items.IndexOf(temp)=-1 then
combobox1.Items.Add(temp);
combobox1.ItemIndex:=0;
end;
#8
avon4563
2006-04-17 08:53
感谢各位的帮忙,谢谢拉
1