免费高清特黄a大片,九一h片在线免费看,a免费国产一级特黄aa大,国产精品国产主播在线观看,成人精品一区久久久久,一级特黄aa大片,俄罗斯无遮挡一级毛片

分享

CListView 類

 紫殿 2011-09-14

ListView 類

.NET Framework 2.0

表示 Windows 列表視圖控件,該控件顯示可用四種不同視圖之一顯示的項集合。

命名空間:System.Windows.Forms
程序集:System.Windows.Forms(在 system.windows.forms.dll 中)

[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
public ref class ListView : public Control
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
public class ListView extends Control
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
public class ListView extends Control

ListView 控件允許您顯示項列表,這些項帶有項文本和圖標(可選)來標識項的類型。例如,Windows 資源管理器的文件列表就與 ListView 控件的外觀相似。它顯示樹中當前選定的文件和文件夾的列表。每個文件和文件夾都顯示一個與之相關的圖標,以幫助標識文件或文件夾的類型。ListViewItem 類表示 ListView 控件中的項。列表中顯示的項可以用五種不同視圖之一顯示。這些項可以顯示為大圖標、小圖標,也可以在垂直列表中顯示為小圖標。這些項也可以具有子項,子項包含與父項相關的信息。詳細信息視圖允許您在網(wǎng)格中顯示項及其子項,并通過列標頭標識要在子項中顯示的信息。平鋪視圖的應用范圍有一定的限制(如下所述),它允許以類似貼瓷磚的方式顯示項及其子項,每塊“瓷磚”(平鋪單元)包含一個大圖標以及圖標旁的文字信息。ListView 支持單選和多選。多重選擇功能使用戶可以按照與 ListBox 控件相似的方式從項列表中進行選擇。另外,用戶還可以激活選定項來執(zhí)行任務。例如,可以使用 ListView 控件顯示應用程序可以打開并使用的文件的列表。用戶可以選擇要打開的文件,然后雙擊它們來激活項,并在應用程序中打開文件。ListView 也可以使用 CheckBoxes 屬性顯示復選框,以使用戶可以選中要對其執(zhí)行操作的項??梢杂酶鞣N方式來使用 ListView 控件。控件可用于顯示來自應用程序、數(shù)據(jù)庫或文本文件的信息。ListView 也可用于獲取來自用戶的信息,例如選擇一組要處理的文件。

ListView 提供了大量可靈活設置外觀和行為的屬性。View 屬性允許您更改項的顯示方式。LargeImageList、SmallImageList 和 StateImageList 屬性允許您指定包含為項顯示的圖像的 ImageList 對象;并且,就 StateImageList 屬性而言,當 CheckBoxes 屬性設置為 true 時,它允許您指定所顯示的復選框。要確定選中了哪些項,可使用 CheckedItems 屬性來訪問 ListView.CheckedListViewItemCollection 集合。Columns 屬性允許訪問ListView.ColumnHeaderCollection,它存儲了當控件的 View 屬性設置為 Details 時顯示的列標頭。通過 Items 屬性,可以在 ListView 中添加和移除項。Items 屬性允許您訪問控件的 ListView.ListViewItemCollection,它提供在控件中操作項的方法。如果需要允許用戶編輯項的文本,可使用 LabelEdit 屬性。當控件包含大量的項時,用戶在經(jīng)過排序的列表中查看這些項通常會更加容易。您可以使用 Sorting 屬性按字母順序對項進行排序。您也可以對 ListView 控件的外觀進行全面的自定義。為實現(xiàn)此目的,可將 OwnerDraw 屬性設置為 true,并處理以下的一個或多個事件:DrawItemDrawSubItem 和DrawColumnHeader。

當 ListView 控件的 View 屬性設置為 Details 時,將使用該控件的許多屬性。AllowColumnReorder 屬性允許 ListView 控件的用戶在運行時重新配置列的順序。FullRowSelect 屬性允許選擇項及其子項(而不僅僅是項)。要在詳細資料視圖中顯示網(wǎng)格線以標識 ListView 中的項及其子項的邊界,可使用 GridLines屬性。HeaderStyle 屬性允許您指定要顯示的列標頭的類型。

除了可用于 ListView 控件的許多屬性外,應用程序還可以使用方法和事件來為 ListView 提供附加功能。通過 BeginUpdate 和 EndUpdate 方法,可在每次添加項時防止控件進行重新繪制,從而在向 ListView 添加多個項時改善性能。如果 ListView 控件顯示的是項和子項,您也許會需要提供用戶用鼠標右鍵單擊子項時的功能。要確定其子項被單擊的項,可使用 GetItemAt 方法。在用戶編輯項后對它們執(zhí)行驗證時,您也許需要向用戶顯示要更改的特定項??梢哉{(diào)用EnsureVisible 方法來確保特定項位于控件的可視區(qū)域中。

如果 LabelEdit 屬性設置為 true,則可以執(zhí)行如下的類似任務:通過為 BeforeLabelEdit 和 AfterLabelEdit 事件創(chuàng)建事件處理程序,在文本更改前后對所編輯的文本進行驗證。要執(zhí)行打開文件或顯示對話框來編輯 ListView 中顯示的項這樣的任務,可以為 ItemActivate 事件創(chuàng)建事件處理程序。如果允許在用戶單擊列標頭時對 ListView 中的項進行排序,則可以為 ColumnClick 事件創(chuàng)建事件處理程序以執(zhí)行排序操作。當 CheckBoxes 屬性設置為 true 時,您可以通過處理ItemCheck 事件來確定項的選中狀態(tài)何時發(fā)生更改。

還可以使用 BackgroundImage 屬性設置 ListView 的背景圖像。為了正確顯示 ListView 控件的背景圖像,您的應用程序必須對其 Main 方法應用STAThreadAttribute。此外,如果帶有背景圖像的 ListView 控件寄宿在 Internet Explorer 中,請在應用程序的清單文件中將 comctl32.dll 6.0 版指定為依賴程序集,確保背景圖像能夠正確顯示。

Note注意

為 ListView 控件設置 Cursor 屬性不會對 .NET Framework 1.1 版及更早版本中的光標外觀產(chǎn)生任何影響。

Windows XP 和 Windows Server 2003 提供了三種功能,以便在您的應用程序調(diào)用 Application.EnableVisualStyles 方法時增強 ListView 控件:平鋪視圖、分組和插入標記。

平鋪視圖通過在大圖標旁邊顯示項及子項的文本,同時兼顧了圖像和文字信息。通過將 View 屬性設置為 View.Tile 可啟用此行為。

分組功能允許您以可視化形式將項分組到相關類別之中。若要啟用此功能,可使用 Groups 屬性將 ListViewGroup 對象添加到 ListView 控件。若要臨時禁用此功能,請將 ShowGroups 屬性設置為 false。

插入標記功能通過指示放置位置,為利用拖放操作調(diào)整項的位置提供了視覺反饋信息。使用通過 InsertionMark 屬性檢索到的 ListViewInsertionMark 對象顯示插入標記。

這些功能僅能在 Windows XP 和 Windows Server 2003 下使用。對于較早期的平臺,與這些功能相關的代碼不會產(chǎn)生任何作用,平鋪視圖將顯示為大圖標視圖,而插入標記和組則不會顯示。在某些情況下,您可能需要編寫代碼來確定是否能夠使用這些功能,并在它們不可用的情況下提供相應的替代功能。提供這些功能的庫與提供操作系統(tǒng)主題功能的庫為同一個庫。若要檢查此庫的可用性,請調(diào)用 FeatureSupport.IsPresent(Object) 方法重載并傳入 OSFeature.Themes值。

下表顯示 ListView 的某些成員以及它們可用于的視圖。

ListView 成員

視圖

Alignment 屬性

SmallIcon 或 LargeIcon

AutoArrange 屬性

SmallIcon 或 LargeIcon

AutoResizeColumn 方法

Details

Columns 屬性

Details 或 Tile

DrawSubItem 事件

Details

FindItemWithText 方法

Details、List 或 Tile

FindNearestItem 方法

SmallIcon 或 LargeIcon

GetItemAt 方法

Details 或 Tile

Groups 屬性

除 List 之外的所有視圖

HeaderStyle 屬性

Details

InsertionMark 屬性

LargeIcon、SmallIcon 或 Tile

下面的代碼示例創(chuàng)建一個 ListView 控件,其中帶有三個指定的 ListViewItem 對象,而這三個對象中的每一項又帶有三個指定的ListViewItem.ListViewSubItem 對象。該示例還創(chuàng)建 ColumnHeader 對象以在詳細資料視圖中顯示子項。在代碼示例中還創(chuàng)建兩個 ImageList 對象,以便為ListViewItem 對象提供圖像。這些 ImageList 對象被添加到 LargeImageList 和 SmallImageList 屬性中。在創(chuàng)建 ListView 控件的過程中,該示例使用了下列屬性:

  • View

  • LabelEdit

  • AllowColumnReorder

  • CheckBoxes

  • FullRowSelect

  • GridLines

  • Sorting

該示例要求已該代碼添加到某個 Form 中,然后在構造函數(shù)或該窗體的其他方法調(diào)用在該示例中創(chuàng)建的方法。該示例還要求名為MySmallImage1、MySmallImage2、MyLargeImage1 和 MyLargeImage2 的圖像位于驅動器 C 的根目錄下。

private:
   void CreateMyListView()
   {
      // Create a new ListView control.
      ListView^ listView1 = gcnew ListView;
      listView1->Bounds = Rectangle(Point(10,10),System::Drawing::Size( 300, 200 ));

      // Set the view to show details.
      listView1->View = View::Details;

      // Allow the user to edit item text.
      listView1->LabelEdit = true;

      // Allow the user to rearrange columns.
      listView1->AllowColumnReorder = true;

      // Display check boxes.
      listView1->CheckBoxes = true;

      // Select the item and subitems when selection is made.
      listView1->FullRowSelect = true;

      // Display grid lines.
      listView1->GridLines = true;

      // Sort the items in the list in ascending order.
      listView1->Sorting = SortOrder::Ascending;

      // Create three items and three sets of subitems for each item.
      ListViewItem^ item1 = gcnew ListViewItem( "item1",0 );

      // Place a check mark next to the item.
      item1->Checked = true;
      item1->SubItems->Add( "1" );
      item1->SubItems->Add( "2" );
      item1->SubItems->Add( "3" );
      ListViewItem^ item2 = gcnew ListViewItem( "item2",1 );
      item2->SubItems->Add( "4" );
      item2->SubItems->Add( "5" );
      item2->SubItems->Add( "6" );
      ListViewItem^ item3 = gcnew ListViewItem( "item3",0 );

      // Place a check mark next to the item.
      item3->Checked = true;
      item3->SubItems->Add( "7" );
      item3->SubItems->Add( "8" );
      item3->SubItems->Add( "9" );

      // Create columns for the items and subitems.
      listView1->Columns->Add( "Item Column", -2, HorizontalAlignment::Left );
      listView1->Columns->Add( "Column 2", -2, HorizontalAlignment::Left );
      listView1->Columns->Add( "Column 3", -2, HorizontalAlignment::Left );
      listView1->Columns->Add( "Column 4", -2, HorizontalAlignment::Center );

      //Add the items to the ListView.
      array<ListViewItem^>^temp1 = {item1,item2,item3};
      listView1->Items->AddRange( temp1 );

      // Create two ImageList objects.
      ImageList^ imageListSmall = gcnew ImageList;
      ImageList^ imageListLarge = gcnew ImageList;

      // Initialize the ImageList objects with bitmaps.
      imageListSmall->Images->Add( Bitmap::FromFile( "C:\\MySmallImage1.bmp" ) );
      imageListSmall->Images->Add( Bitmap::FromFile( "C:\\MySmallImage2.bmp" ) );
      imageListLarge->Images->Add( Bitmap::FromFile( "C:\\MyLargeImage1.bmp" ) );
      imageListLarge->Images->Add( Bitmap::FromFile( "C:\\MyLargeImage2.bmp" ) );

      //Assign the ImageList objects to the ListView.
      listView1->LargeImageList = imageListLarge;
      listView1->SmallImageList = imageListSmall;
      
      // Add the ListView to the control collection.
      this->Controls->Add( listView1 );
   }

private void CreateMyListView()
{
    // Create a new ListView control.
    ListView listView1 = new ListView();
    listView1.set_Bounds(new Rectangle(new Point(10, 10), 
        new Size(300, 200)));

    // Set the view to show details.
    listView1.set_View(View.Details);

    // Allow the user to edit item text.
    listView1.set_LabelEdit(true);

    // Allow the user to rearrange columns.
    listView1.set_AllowColumnReorder(true);

    // Display check boxes.
    listView1.set_CheckBoxes(true);

    // Select the item and subitems when selection is made.
    listView1.set_FullRowSelect(true);

    // Display grid lines.
    listView1.set_GridLines(true);

    // Sort the items in the list in ascending order.
    listView1.set_Sorting(SortOrder.Ascending);

    // Create three items and three sets of subitems for each item.
    ListViewItem item1 = new ListViewItem("item1", 0);

    // Place a check mark next to the item.
    item1.set_Checked(true);

    item1.get_SubItems().Add("1");
    item1.get_SubItems().Add("2");
    item1.get_SubItems().Add("3");

    ListViewItem item2 = new ListViewItem("item2", 1);
    item2.get_SubItems().Add("4");
    item2.get_SubItems().Add("5");
    item2.get_SubItems().Add("6");

    ListViewItem item3 = new ListViewItem("item3", 0);

    // Place a check mark next to the item.
    item3.set_Checked(true);

    item3.get_SubItems().Add("7");
    item3.get_SubItems().Add("8");
    item3.get_SubItems().Add("9");

    // Create columns for the items and subitems.
    listView1.get_Columns().Add("Item Column", -2, 
        HorizontalAlignment.Left);
    listView1.get_Columns().Add("Column 2", -2, HorizontalAlignment.Left);
    listView1.get_Columns().Add("Column 3", -2, HorizontalAlignment.Left);
    listView1.get_Columns().Add("Column 4", -2, HorizontalAlignment.Center);

    //Add the items to the ListView.
    listView1.get_Items().AddRange(new ListViewItem[] { item1, item2, 
        item3 });

    // Create two ImageList objects.
    ImageList imageListSmall = new ImageList();
    ImageList imageListLarge = new ImageList();

    // Initialize the ImageList objects with bitmaps.
    imageListSmall.get_Images().Add(Bitmap.FromFile(
        "C:\\MySmallImage1.bmp"));
    imageListSmall.get_Images().Add(Bitmap.FromFile(
        "C:\\MySmallImage2.bmp"));
    imageListLarge.get_Images().Add(Bitmap.FromFile(
        "C:\\MyLargeImage1.bmp"));
    imageListLarge.get_Images().Add(Bitmap.FromFile(
        "C:\\MyLargeImage2.bmp"));

    //Assign the ImageList objects to the ListView.
    listView1.set_LargeImageList(imageListLarge);
    listView1.set_SmallImageList(imageListSmall);

    // Add the ListView to the control collection.
    this.get_Controls().Add(listView1);
} //CreateMyListView

System.Object 
   System.MarshalByRefObject 
     System.ComponentModel.Component 
       System.Windows.Forms.Control 
        System.Windows.Forms.ListView
此類型的任何公共靜態(tài)(Visual Basic 中的 Shared)成員都是線程安全的,但不保證所有實例成員都是線程安全的。

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是對每個平臺的所有版本都提供支持。有關受支持版本的列表,請參見系統(tǒng)要求。

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內(nèi)容,請點擊一鍵舉報。
    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多