起步软件技术论坛-X3

 找回密码
 立即注册
搜索
查看: 137|回复: 3

两个ListView问题?**

[复制链接]
发表于 2008-8-5 17:17:40 | 显示全部楼层 |阅读模式
1、ListView里边的checkbox选中事件是什么?或者checkbox选中时,对应的ListView项选中?
    2、ListView有没有显示值(Caption),与关键字这样的说法?
回复

使用道具 举报

发表于 2008-8-5 17:30:05 | 显示全部楼层
TListItem.Checked

Determines whether a check mark appears next to the list item.

property Checked: Boolean;

Description

Use Checked to indicate whether the list item represents a selected option by displaying a check mark next to the item in the list view. When Checked is True, a check mark appears next to the item. When Checked is False, no check mark appears.

Note:        Set the CheckBoxes property of the ListView to True before using the Checked property.
回复 支持 反对

使用道具 举报

发表于 2008-8-5 17:34:12 | 显示全部楼层
procedure TForm1.FormCreate(Sender: TObject);

const
  Names: array[0..5, 0..1] ofstring = (
    ('Rubble', 'Barney'),
    ('Michael', 'Johnson'),
    ('Bunny', 'Bugs'),
    ('Silver', 'HiHo'),
    ('Simpson', 'Bart'),
    ('Squirrel', 'Rocky')
    );

var
  I: Integer;
  NewColumn: TListColumn;
  ListItem: TListItem;
  ListView: TListView;
begin
  ListView := TListView.Create(Self);
  with ListView do
  begin
    Parent := Self;
    Align := alClient;

    ViewStyle := vsReport;

    NewColumn := Columns.Add;
    NewColumn.Caption := 'Last';
    NewColumn := Columns.Add;
    NewColumn.Caption := 'First';

    for I := Low(Names) to High(Names) do
    begin
      ListItem := Items.Add;
      ListItem.Caption := Names[I][0];
      ListItem.SubItems.Add(Names[I][1]);
    end;
  end;
end;
回复 支持 反对

使用道具 举报

发表于 2008-8-5 17:45:28 | 显示全部楼层
问题1,Change事件
procedure TMainForm.ListView1Change(Sender: TObject; Item: TListItem; Change: TItemChange);
begin
  if Item.Checked then Dialogs.ShowMessage('OK');
end;

问题2
没有关键字与显示值的说法。但有SubItems属性可以存放多个子项值。
s := ListView1.Items[0].Caption;   
s := ListView1.Items[0].SubItems.Strings[0];
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Justep Inc.

GMT+8, 2025-7-20 08:28 , Processed in 0.043045 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表