高分求救:如何在Treeview中不重复添加相同的项目? 找erp软件
我有一表,要将表的内容导入Treeview:
姓名
张三
张三
李四
李四
李四
王五
要求:如果treeview中已有相同的姓名,就不导入,即每个姓名只在treeview中出现一次,程序怎样写,请各位大侠帮帮我。
2楼: 我自己顶一下,在线等啊,特着急!!! 如erp软件
3楼: 查询时候Group By 姓名
4楼: 写一个函数:
==============================================
function A.checkaSomeName(Parent:ttreeNode;const Atext:string):boolean;
var
i:integer;
begin
result:=true;
for i:=0 to pred(parent.count) do
if parent[i].text=Atext then
begin
result:=false;
break;
end;
end;
==============================================
这个函数完全可以。
5楼: 查詢一次表中是否有該名字就行了
close;
sql.clear
sql.add(''select * from 表名 where 姓名=''''''+trim(edit1.Text)+'''''''');
open;
if (adoquery.RecordCount > 0) then
begin
showmessage(''已存在'');
exit;
end
else
.......
6楼: 可以先从数据方面进行过滤:
select distinct name from tablename
库存管理软件版7楼: 插入之前先查找名称是否存在
Function FindNode(ParentNode:TTreeNode;NodeScript:string):TTreeNode;
var
Node:TTreeNode;
begin
result:=nil;
if ParentNode =nil then
Node := Tree.Items.GetFirstNode
else
Node:=ParentNode.getFirstChild;
while Node <> nil do
begin
if Node.Text = NodeScript then
begin
Result:=Node;
break;
end;
Node:=Node.getNextSibling;
end;
end;
8楼: 如果是数据库的数据,那么查询的时候就生成不重复的数据
要不就得针对TREEVIEW操作了
9楼: 太谢谢各位了,搞定!!给大家散分了。