C#listview Properties and actual operation of the control

Source: Internet
Author: User
Tags key case

Common Properties:

View Sets or returns the type of views for a control

Value Description

1-lvwicon icon Type

2-lvwsmallicon Small Icon Type

3-lvwlist list Types

4-lvwreport Report Types

Arrange the icon arrangement of the returned control after setting (valid in Icon view)

Value Description

1-lvwnone not arranged

2-lvwautoleft automatically on the right

3-lvwautotop automatically on the left

Icons, Smallicons, columnheadericons properties

Icons The icon that specifies the icon view when the ImageList is bound

Smallicons, columnheadericons the icon associated with the ImageList when specifying the list view

Picture, PictureAlignment Property

Specify the background picture and layout style of the ListView control, respectively ListItems (Index) property

The ListItems property is a collection of list items in a ListView control.

Index is used to specify an object in the list item collection, and we can think of this object as a reference to a row ListItems the collection's properties

1. Text setting or returning display text

2. Key keyword

3. Index number

4. Icon, SmallIcon a cell when different views are displayed

5. Checked give checkboxes to play √

6. Selected the selected state

7. ListSubItems (Index) collection we can think of this set as a reference to a cell in this row text sets or returns the contents of a cell display Reporticon set the icon for a cell

8. SubItems (index) Sets or returns the cell text = = ListSubItems (index). Text ColumnHeaders (Index) property

The ColumnHeaders property is a collection of column headers in a ListView control

1. Text Display title

2. Key

3. Index

4. Icon specifies the title

5. Alignment Specifies the alignment of the index column (note: The first column is the list item cannot be specified)

6. Position returns the index of the top column

7. Subitemindex returns the ListSubItem index Textbackgroud property of the specified column

Determines whether the background of text is transparent or the background color value of the ListView 0 lvwtransparent Transparent 1 lvw opaque (with the background color of the ListView)

ghosted property logic Determines whether the virtual HideColumnHeaders property

Hide Header Labelwrap Property Labels Use this property to fullrowselect the entire row when you switch to View.LargeIcon or View.SmallIcon

HOTTRACKING hotspot Tracking mouse pointer automatically adjusts to hand type Hoverselection Property auto Focus mouse pointer automatically adjusts to hand type Allowcolumnreorder property

When the value is set to. T., the user can use the mouse to select 1 columns to be dragged to another place to rearrange the sorted property to. T.

List by alphabetical order common methods:

Listitems.add (Index,key,text,icon,smallicon) Adds a list item to ListItems.

Index Insert list item number key Insert list item keyword

Text Insert list item The icon that is required to display when the icon view is displayed

SmallIcon the icon that is required to be displayed when the small icon view is Clear

Clears all list items in the ListItems collection remove clears the selected row L1=thisform.view1 L1.listitems.remove (L1.selectedItem.index) Allowcolumnreorder property

When the value is set to. T., users can rearrange common events by dragging the 1 columns to other places with the mouse selected:

AfterLabelEdit occurs after editing the currently selected list Object BeforeLabelEdit before editing the currently selected list object

ItemClick A parameter item occurs when you click a list object AfterLabelEdit: is triggered when the label of the ListItem object is edited.

BeforeLabelEdit: Edit the label of the ListItem object to start. ColumnClick: Triggered when a column header is clicked. parameter, you can get the column object that you clicked. Typically used for sorting.

ItemClick: Fires when a row or a listitem is clicked. You can get the ListItem object that you clicked in the parameters. Method FindItem: Searches for ListItem objects.

Parameter: string: Search string. Value: Search in which part of ListItem (Lvwtext, Lvwsubitem, Lvwtag); index: the location where the search begins.

Match: the matching method. HitTest: Retrieves the ListItem object at a specific coordinate. The instance in VB Private Sub Form_Load () ' ensures that the view property of the ListView control is report view.

Listview1.view=lvwreport ' Add three columns. LISTVIEW1.COLUMNHEADERS.ADD, "name", "name" ListView1.ColumnHeaders.Add, "sex", "gender"

LISTVIEW1.COLUMNHEADERS.ADD, "Age", "ages", add ListItem objects to the control. Dim itmx as ListItem ' Add column1 name.

Set Itmx=listview1.listitems.add (1, "ZL", "tension") ' use Subitemindex to associate subitem with the correct columnheader.

Use the keyword ("Sex") to specify the correct columnheader.

Itmx.subitems (Listview1.columnheaders ("Sex"). Subitemindex) = "Male" uses the ColumnHeader keyword to associate the subitems string with the ' correct ColumnHeader '.

Itmx.subitems (Listview1.columnheaders ("Age"). Subitemindex) = "+" Set itmx=listview1.listitems.add (1, "LF", "Li Fang")

Itmx.subitems (Listview1.columnheaders ("Sex"). Subitemindex) = "Male" Itmx.subitems (listview1.columnheaders ("Age"). Subitemindex) = "Set"

Itmx=listview1.listitems.add (1, "WW", "Wang Wei") Itmx.subitems (Listview1.columnheaders ("Sex"). Subitemindex) = "Male"

Itmx.subitems (Listview1.columnheaders ("Age"). Subitemindex) = "All" End sub Private Sub Listview1_columnclick (ByVal ColumnHeader as

Comctllib.columnheader) Select Case columnheader.key case "Sex":

Listview1.sortkey=1 listview1.sortorder=lvwascending listview1.sorted=true case ' age ':

listview1.sortkey=2 listview1.sortorder=lvwascending listview1.sorted=true End Select End Sub

Example two Private Sub userform_initialize () ListView1.ColumnHeaders.Add,,

"QQ number" ' Add QQ Number column LISTVIEW1.COLUMNHEADERS.ADD,,

"What does it say?" added the column ListView1.ColumnHeaders.Add,

"From where" ' Add from where column Listview1.view = Lvwreport ' setting is displayed as report format End Sub code Description:

1. Column is represented in the worksheet. In the ListView control, the ColumnHeaders object is used to manipulate the column, and the Add new column can be used with the Add method of the ColumnHeaders object.

Specific as follows:

ListView1.ColumnHeaders.Add ordinal, unique string identifier, column label display text, column width, column content alignment, the icon ordinal used.

As in this example:

LISTVIEW1.COLUMNHEADERS.ADD,, "QQ No."

2. The View property of the ListView control determines how it is displayed,

Specific as follows:

Listview1.view = Lvwicon ' icon display

Listview1.view = Lvwsmallicon ' small icon display

Listview1.view = Lvwlist ' list display

Listview1.view = Lvwreport ' report display

Add Effect: Sample file:

Code: Private Sub userform_initialize () ' Declare variable type Dim ITM as ListItem ' Add QQ number column,

Column widths are one-third of the total width, left-aligned LISTVIEW1.COLUMNHEADERS.ADD,

, "QQ number", LISTVIEW1.WIDTH/3, Lvwcolumnleft ' Add it called column,

Column widths of One-third of the total width, center-aligned LISTVIEW1.COLUMNHEADERS.ADD,

, "LISTVIEW1.WIDTH/3", Lvwcolumncenter ' Add from where column,

Column widths are one-third of the total width, right-aligned LISTVIEW1.COLUMNHEADERS.ADD,

, "from where", LISTVIEW1.WIDTH/3, Lvwcolumnright ' Set display mode for report format Listview1.view = Lvwreport ' Show Table lines

Listview1.gridlines = True ' Sets the loop, fills the record for i = 1 to [A65536]. End (Xlup). Row ' Add record Set ITM = LISTVIEW1.LISTITEMS.ADD () '

Adding a record row header definition produces a new record for the new line ITM. Text = Cells (i, 1) ' Add record text of record description ITM. SubItems (1) = Cells (i, 2) '

Add the contents of the first field of the record, and display ITM on the second column. SubItems (2) = Cells (i, 3) Next I End Sub

Code Description:

1, ListView1 the Gridlines property is true when the table line is displayed, False does not show the table line.

2. In the ListView control, add the record to be implemented by the ListItems collection object, as in this example set ITM = ListView1.ListItems.Add ()

3, the content of the first column is added by the Text property, and later columns are added through the subitems object.

2nd Column SubItems (1)

The 3rd column is subitems (2) .....

4, the 1th column in the ListView control can only be left-justified, and cannot take other alignment

5. Cell reference: Cells (row, column) Add column listView1.ColumnHeaders.Add add row listView1.ListItems.Ad

Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Linq;
Using System.Text;
Using System.Windows.Forms;

Namespace ListView
{
public partial class Form1:form
{
Public Form1 ()
{
InitializeComponent ();
}

private void Butzengjia_click (object sender, EventArgs e)
  {
        LISTVIEW1.ITEMS.ADD (txbxingming. Text);
       LISTVIEW1.ITEMS[LISTVIEW1.ITEMS.COUNT-1]. SubItems.Add (Txbxingbie. Text);
       LISTVIEW1.ITEMS[LISTVIEW1.ITEMS.COUNT-1]. SubItems.Add (txbnianling. Text);
       LISTVIEW1.ITEMS[LISTVIEW1.ITEMS.COUNT-1]. SubItems.Add (Txbminzu. Text);
       txbxingming. Text = "";
       txbxingbie. Text = "";
       txbnianling. Text = "";
       txbminzu. Text = "";
 }

private void Butshanchu_click (object sender, EventArgs e)
{
for (int i = 0; i < ListView1.Items.Count; i++)
{
if (Listview1.items[i]. Subitems[0]. Text = = txbxingming. Text)
ListView1.Items.RemoveAt (i);
}
Txbxingming. Text = "";
Txbxingbie. Text = "";
Txbnianling. Text = "";
Txbminzu. Text = "";
}
}
}

C#listview Properties and actual operation of the control

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.