5,387
社区成员
发帖
与我相关
我的任务
分享
→增加一行:
with ListView1 do
begin
ListItem:=Items.Add;
ListItem.Caption:='第一列内容';
ListItem.SubItems.Add('第二列内容');
end;
→清空ListView1:
ListView1.Items.Clear;
→得到当前被选中行的行的行号以及删除当前行:
For i:=0 to ListView1.Items.Count-1 Do
If ListView1.Items[i].Selected then //i=ListView1.Selected.index
begin
ListView1.Items.Delete(i); //删除当前选中行
end;
当然,ListView有OnSelectItem事件,可以判断选择了哪行,用个全局变量把它赋值出来。
→读某行某列的操作:
Edit1.Text := listview1.Items[i].Caption; //读第i行第1列
Edit2.Text := listview1.Items[i].SubItems.strings[0]; //读第i行第2列
Edit3.Text := listview1.Items[i].SubItems.strings[1]; //读第i行第3列
以次类推,可以用循环读出整列。
→将焦点上移一行:
For i:=0 to ListView1.Items.Count-1 Do
If (ListView1.Items[i].Selected) and (i>0) then
begin
ListView1.SetFocus;
ListView1.Items.Item[i-1].Selected := True;
end;
var
excelTemp, sheetTemp: OleVariant;
try
excelTemp := CreateOleObject('Excel.Application');
except
Exit;
end;
excelTemp.WorkBooks.Open(sFileName);
sheetTemp := excelTemp.WorkBooks[1].WorkSheets[1];
stmp := Trim(sheetTemp.cells[1, 1]);//需要取的excel表格坐标
if Pos('售票报表', stmp) = 0 then
begin
Result := -1;
Exit;
end;