TListItem *Item;

    for (int i = 0; i < 10; i++)
    {
        Item = ListView1->Items->Add();
        Item->Caption = i;
    }
    ListView1->Items->Item[0]->Selected = true;

 

ListView1->ViewStyle=vsReport;

TListColumn *pCol=0;
pCol=ListView1->Columns->Add();
pCol->Caption="学号";
pCol=ListView1->Columns->Add();
pCol->Caption="姓名";
pCol=ListView1->Columns->Add();
pCol->Caption="成绩";
TListItem *pItem=0;
//添加9行
for(int i=0;i<9;i++)
{
pItem=ListView1->Items->Add();
//第1列
pItem->Caption=String(i+1);
//第2列
pItem->SubItems->Add("学生"+String(i+1));
//第3列
pItem->SubItems->Add("bcb群[4670-3864]");
}

ListView1->Items->Item[i]->Caption = "第i行第1列的值";
ListView1->Items->Item[i]->SubItems->Strings[0]= "第i行第2列的值";
ListView1->Items->Item[i]->SubItems->Strings[1]= "第i行第3列的值";
ListView1->Items->Item[i]->SubItems->Strings[2]= "第i行第4列的值";

     ListView1->Items->Item[0]->Caption;

ListView1->Items->Item[0]->EditCaption();

ListView1->Items->Item[0]->EditCaption();

ListView取得EditCaption后EDITLABEL句柄

    ListView1->Items->Item[0]->EditCaption();
    String atext = ListView1->Items->Item[0]->Caption;
    ListView1->SetFocus();
    HWND ahandle = (HWND) SendMessage(ListView1->Handle, LVM_EDITLABEL, (WPARAM)0, (LPARAM)0);

    int SelLen = atext.Pos(".") - 1;
    SendMessage(ahandle, EM_SETSEL, 0, SelLen);
    SendMessage(ahandle, EM_SCROLLCARET, 0, 0);

 

修改ListView的内容

    ListView1->Column[0]->Caption = "标题1";
    ListView1->Column[1]->Caption = "标题2";

    ListView1->Items->Item[0]->Caption = "第1行第1列的值";
    ListView1->Items->Item[0]->SubItems->Strings[0] = "第1行第2列的值";
    ListView1->Items->Item[0]->SubItems->Strings[1] = "第1行第3列的值";

 

    //udpate title
    this->ListView1->Columns->Items[0]->Caption = "a";
    this->ListView1->Columns->Items[1]->Caption = "b";
    this->ListView1->Columns->Items[2]->Caption = "c";

 

    ListView1->ViewStyle = vsReport;
    TListColumn * Item;
    for ( int i = 0; i < 20; i++ )
    {
        Item = ListView1->Columns->Add( );
        Item->Caption = i;
    }

    TListItem * pItem = 0;
    for ( int i = 0; i < 9; i++ )
    {
        pItem = ListView1->Items->Add( );
        // 第1列
        pItem->Caption = String( i + 1 );
        for ( int j = 0; j < ListView1->Columns->Count; j++ )
        {
            // 第2..n列
            pItem->SubItems->Add( String( j + 1 ) );
        }
    }

 

复选框

Specifies whether check boxes appear next to the items in the list view.

Set Checkboxes to true to make check boxes appear next to the list items when ViewStyle is vsList or vsReport. Each line in the list displays a single check box.

全选/全不选

    for (int i = 0; i < ListView1->Items->Count; i++)
    {
        ListView1->Items->Item[i]->Checked = chk1ALL->Checked;
    }

 

posted on 2014-08-20 22:05  lypzxy  阅读(272)  评论(0编辑  收藏  举报