楼主,你其实可以自己额外的再建立一个 TStrings 变量在向 TListView 组件里添加信息的同时把那条数据的自动编号添加到这个变量里里,这样他俩的 Index 不就同步了吗,然后你 用 ListView.Selected.Index 就可以同步的在 TStrings 里找到对应的自动编号了啊,不一定非要单恋一只花吧给你个简单的例子,其实一点也不难,也没有增加多大的工作量var strList: TStrings; i: Integer; begin strList:= TStringList.Create; ListView.Clear; for i:= 0 to 3 do begin with ListView.Items.Add do begin strList.Append(IntToStr(i)); Caption:= 'String' + IntToStr(i); end; end; ShowMessage(strList.Text); end;
procedure Tform_fw_select.BitBtn1Click(Sender: TObject); var p:^integer; begin if apart_list.Selected =nil then exit; p:=Apart_list.Selected.Data; fwid:=p^; recordset_temp.SQL.Clear ; recordset_temp.SQL.Add ('Select * From [FWXM] Where [FW_ID]=' + inttostr(p^)); recordset_temp.Open ; if recordset_temp.RecordCount <>0 then begin fwname:=recordset_temp.Fields[1].AsString ; fwmoney:=recordset_temp.Fields[3].AsFloat ; recordset_temp.Close; close; end; recordset_temp.close ; end; 我们尽量还是用控件ADOquery来操作吧
我软件也有这用法。我直接用 caption 设置为 0 宽度,里面放 ID 值
最方便的方法应该是像6楼说的,设置1列Column的Width属性为0用listview.selected取得选中的行後,caption就是第0列,其它列用SubItems[i]取得0<= i < n
strList: TStrings;
i: Integer;
begin
strList:= TStringList.Create;
ListView.Clear;
for i:= 0 to 3 do
begin
with ListView.Items.Add do
begin
strList.Append(IntToStr(i));
Caption:= 'String' + IntToStr(i);
end;
end;
ShowMessage(strList.Text);
end;
var
p:^integer;
begin
if apart_list.Selected =nil then exit;
p:=Apart_list.Selected.Data;
fwid:=p^;
recordset_temp.SQL.Clear ;
recordset_temp.SQL.Add ('Select * From [FWXM] Where [FW_ID]=' + inttostr(p^));
recordset_temp.Open ;
if recordset_temp.RecordCount <>0 then
begin
fwname:=recordset_temp.Fields[1].AsString ;
fwmoney:=recordset_temp.Fields[3].AsFloat ;
recordset_temp.Close;
close;
end;
recordset_temp.close ;
end;
我们尽量还是用控件ADOquery来操作吧
还有一个最大宽度设置为1 就可以了