检查listbox上是否有重复项,如有,则删掉前面一个,如:
dev001---这个要删掉
dev002
dev003
dev001
dev004---这个要删掉
devoo4
解决方案 »
- 在DBGridEh中如何获取正在编辑的、尚未提交的单元格的内容?
- IdTCPServer多个客户端同时访问的问题
- TComboBox控件的Text属性为何不好用?
- delphi程序使用中的问题!高手进来看一下!
- Delphi7操作记录文件的问题
- 如何用delphi控制Access中的ole字段类型
- 怎么捕捉SocketConnectio的连接Error的异常啊(急)
- 在局域网中如何判断是否连到服务器?(用delphi)
- 我想在状态栏上放个小图片,怎么作,或者大家推荐相关的控件,谢谢
- 如果你是一个软件公司的老总,你会招聘兼职的Delphi高手呢,还是才入门的全职Delphi新手?(薪金一样)
- delphi+sql技術論壇群 10998525 歡迎加入探討
- 关于Dbgrid中显示方式的问题?
if (listbox.items[i] = 'dev001') or (listbox.items[i] = 'dev001') then
listbox.items[i].delete;
i:Integer;
iIndex:Array of Integer;
s:TStringList;
begin
SetLength(iIndex,0); s:=TStringList.Create;
try
for i:=0 to ListBox1.Count-1 do
begin
if s.IndexOf(ListBox1.Items[i])>=0 then
begin
SetLength(iIndex,Length(iIndex)+1);
iIndex[High(iIndex)]:=i;
end
else begin
s.Add(ListBox1.Items[i]);
end;
end;
finally
s.Free;
end; for i:=High(iIndex) DownTo 0 do
ListBox1.Items.Delete(iIndex[i]); iIndex:=nil;
end;
然后检查后复制过去
比如
var
Combobox1: TCombobox;
i,j,k :integer;-------
Combobox1.items.clear;for i := 0 to ListBox1.items.count-1 do
Combobox1.items.add(ListBox1.items.string[i]);listbox1.Items.Clear;for i :=0 to combobox1.Items.Count-1 do
begin
for j := 0 to listbox1.Items.Count-1 do
begin
if combobox1.Items[i]<>listbox1.items[j] then
listbox1.Items.Add(combobox1.Items[j]);
end;
end;
改正如下
var
Combobox1: TCombobox;
i,j: integer;
Str: string;-------
Combobox1.items.clear;for i := 0 to ListBox1.items.count-1 do
Combobox1.items.add(ListBox1.items.string[i]);listbox1.Items.Clear;for j:=0 to (Combobox1.Items.Count-1) do
begin
Str := combobox1.items[j];
if listbox1.indexof(Str)=-1 then
listbox1.Items.Add(Str);
end;
procedure TForm1.Button1Click(Sender: TObject);
var i,j:integer;
begin
ListBox2.Items.Clear;
j:=ListBox1.Items.Count-1;
for i:=0 to j do
begin
if ListBox2.Items.IndexOf(ListBox1.Items.Strings[j-i])>0 then continue
else ListBox2.Items.Add(ListBox1.Items.Strings[j-i]);
end;
ListBox1.Items.Clear;
j:=ListBox2.Items.Count-1;
for i:=0 to j do ListBox1.Items.Add(ListBox2.Items.Strings[j-i]);
end;
dev001 x001 ---这个要删掉
dev002 x001
dev003 x002
dev001 x007
dev004 x009 ---这个要删掉
devoo4 x002也就是说,listbox上的每一项,包括两段数据,一段为标识(如dev001等),一段为所属区(如x001等),中间以空格分开,如标识有重复.就删掉前一个
上面标识为dev001和dev004有重复,就删掉前面的一个,如上面我标的,结果在listbox1上如下
dev002 x001
dev003 x002
dev001 x007
devoo4 x002
不行