8.16 Creating ListView Columns

 <  Day Day Up  >  

8.16 Creating ListView Columns

You want to add columns that are displayed in the Details ListView mode.


Technique

Using the form designer, select the ListView whose columns you want to edit and invoke the ColumnHeader collection editor using the Columns property in the property browser. Click the Add button in the editor to add new columns. You can change the order of the columns using the up and down arrows. You can also programmatically add columns by creating new ColumnHeader objects and calling the Add method of the Columns collection defined in the ListView . Each column indexes a list view item's SubItems collection for its display.

Comments

The Details view is for users who want a little more information about the items they are working with. Unlike the other views, which simply display an item label and optional icon, the Details view allows you to create any number of additional columns of information.

You add new columns by accessing the Columns collection of a ListView . Like most other control collections, it contains methods that allow you to add or remove objects programmatically and also contains its own visual collection editor accessed from the property browser. You use ColumnHeader objects as the collections object type, although the Add method of the collection is overloaded to also accept a simple string.

Each ListViewItem object added to the ListView contains a corresponding SubItems collection whose indices coincide with the columns of the list view. The first item within the SubItems collection is the label of the item that is shown regardless of the mode the ListView is in. In other words, even if the ListView does not contain extra column information, the SubItems collection of each ListViewItem still contains at least one object. Also, just as you're able to programmatically or visually add a ListViewItem and ColumnHeader object to their corresponding collections, you can also programmatically or visually add a ListViewSubItem object to the SubItems collection.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net