如何判断ListBox中的项有没有被选中?

snaker2001 2001-08-07 01:17:55
我想判断ListBox中所列出的项,哪项被选中?请指点!
...全文
1730 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
szkingrose 2001-08-07
  • 打赏
  • 举报
回复
listbox1.selcount
为选中的总数,如果小于1则没有选中,太简单了
ch81 2001-08-07
  • 打赏
  • 举报
回复
ListBox1.Selected[Index: Integer]: Boolean;
可判断那一项被选中了。
var

F: File;
i: Integer;
begin
for i := 0 to (FileListBox1.Items.Count - 1) do begin
try
if FileListBox1.Selected[i] then
begin
if not FileExists(FileListBox1.Items.Strings[i]) then begin
MessageDlg('File: ' + FileListBox1.Items.Strings[i] +
' not found', mtError, [mbOk], 0);
Continue;
end;
AssignFile(F, FileListBox1.Items.Strings[i]);

Reset(F, 1);
ListBox1.Items.Add(IntToStr(FileSize(F)));
CloseFile(F);
end;
finally
{ do something here }
end;
end;
end;
trainbox 2001-08-07
  • 打赏
  • 举报
回复
用listbox1.itemindex来判断
listbox1.itemindex=-1没有选中的项
listbox1.itemindex>=0有选中的项
yellowbb 2001-08-07
  • 打赏
  • 举报
回复
listbox中selected属性
listbox1.selected

5,928

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧