如何显示如下格式的listview.
序号 名称
0 aaa
1 bbb
2 ccc
3 ddd
.. ...
listview显示选择了report,定义了2列,分别为序号,名称。
现在要把从数据库中取出的数据填充进去。
序号是根据数据条数计算出来的,名称是截取出来的字符串。数据库内部的格式为aaa;bbb;ccc;ddd;...;
很着急呀。各位知道的给帮帮忙?
序号 名称
0 aaa
1 bbb
2 ccc
3 ddd
.. ...
listview显示选择了report,定义了2列,分别为序号,名称。
现在要把从数据库中取出的数据填充进去。
序号是根据数据条数计算出来的,名称是截取出来的字符串。数据库内部的格式为aaa;bbb;ccc;ddd;...;
很着急呀。各位知道的给帮帮忙?
对于aaa,bbb:ccc:ddd不知这你这是一条记录还是多条,如果是多条就分开一条条写,可以用一个stringlist来处理。
类似这样,具体处理的自己修改一下吧
with ListView1.Items.Add do
begin
Caption := FOtherCostInfo.othername;
SubItems.Add(FOtherCostInfo.othercost);
end;
s:tlistitem;
i:Integerp
begin
循环{
//======先准备号填充数据;
s:=listview.items.add;
s.caption:='序号值';
s.subitems.add('名称值')
}
end;
现在不知道怎么实现拖拽的效果,是托行,不是托列。
i:Integer;
strlist:TStringList;
begin
strlist:=TStringList.Create;
strlist.Delimiter := ';';
strlist.DelimitedText := 'aaa;bbb;ccc;ddd';
for i:=0 to strlist.Count-1 do
begin
with ListView1.Items.Add do
begin
Caption := IntToStr(i);
SubItems.Add(strlist.Strings[i]);
end;
end;
end;
要不我在开一贴呀?
var
Form1: TForm1;
Draging:Boolean=false;
BeginDragItem:TListItem;
implementation{$R *.dfm}procedure TForm1.ListView1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
BeginDragItem:=ListView1.GetItemAt(x,y);
Draging:=true;
end;procedure TForm1.ListView1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
item:TListitem;
str:string;
begin
if Draging then
begin
if BeginDragItem<>nil then
begin
item:=ListView1.GetItemAt(x,y);
if item<>nil then
begin
str:=BeginDragItem.SubItems[0];
BeginDragItem.SubItems[0]:=item.SubItems[0];
item.SubItems[0]:=str;
item.Selected:=true;
end;
end;
end;
end;