Este tema aún no ha recibido ninguna valoración - Valorar este tema

ColumnHeader (Clase)

Actualización: noviembre 2007

Muestra un solo encabezado de columna en un control ListView.

Espacio de nombres:  System.Windows.Forms
Ensamblado:  System.Windows.Forms (en System.Windows.Forms.dll)
[TypeConverterAttribute(typeof(ColumnHeaderConverter))]
public class ColumnHeader : Component, 
	ICloneable
/** @attribute TypeConverterAttribute(ColumnHeaderConverter) */
public class ColumnHeader extends Component implements ICloneable
public class ColumnHeader extends Component implements ICloneable

Un encabezado de columna es un elemento de un control ListView que contiene el texto del encabezado. Se pueden agregar objetos ColumnHeader a un control ListView mediante el método Add de la clase ListView.ColumnHeaderCollection. Para agregar un grupo de columnas a ListView, se puede utilizar el método AddRange de la clase ListView.ColumnHeaderCollection. Se puede utilizar la propiedad Index de la clase ColumnHeader para determinar dónde se encuentra ColumnHeader en ListView.ColumnHeaderCollection.

ColumnHeader proporciona las propiedades Text y TextAlign para establecer el texto que se muestra en el control y la alineación del texto en el encabezado de columna. Para determinar si existe una asociación entre ColumnHeader y un control ListView, se puede hacer referencia a la propiedad ListView. Si se desea copiar ColumnHeader para utilizarlo en otro control ListView, se puede emplear el método Clone.

En el siguiente ejemplo de código se muestra cómo se inicializa un control ListView. En el ejemplo se crean objetos ColumnHeader y se establecen las propiedades Text, TextAlign y Width del encabezado de columna. En el ejemplo también se agregan elementos y subelementos al control ListView. Para ejecutar este ejemplo, pegue el código siguiente en un formulario y llame al método PopulateListView desde el constructor del formulario o desde el controlador de eventos Load.

	private void PopulateListView()
	{
		ListView1.Width = 270;
		ListView1.Location = new System.Drawing.Point(10, 10);

		// Declare and construct the ColumnHeader objects.
		ColumnHeader header1, header2;
		header1 = new ColumnHeader();
		header2 = new ColumnHeader();

		// Set the text, alignment and width for each column header.
		header1.Text = "File name";
		header1.TextAlign = HorizontalAlignment.Left;
		header1.Width = 70;

		header2.TextAlign = HorizontalAlignment.Left;
		header2.Text = "Location";
		header2.Width = 200;

		// Add the headers to the ListView control.
		ListView1.Columns.Add(header1);
		ListView1.Columns.Add(header2);

		// Populate the ListView.Items property.
		// Set the directory to the sample picture directory.
		System.IO.DirectoryInfo dirInfo = 
			new System.IO.DirectoryInfo(
			"C:\\Documents and Settings\\All Users" +
			"\\Documents\\My Pictures\\Sample Pictures");
		

		// Get the .jpg files from the directory
		System.IO.FileInfo[] files = dirInfo.GetFiles("*.jpg");

		// Add each file name and full name including path
		// to the ListView.
		if (files != null)
		{
			foreach ( System.IO.FileInfo file in files )
			{
				ListViewItem item = new ListViewItem(file.Name);
				item.SubItems.Add(file.FullName);
				ListView1.Items.Add(item);
			}
		}
	}


private void PopulateListView()
{
    listView1.set_Width(270);
    listView1.set_Location(new System.Drawing.Point(10, 10));
    // Declare and construct the ColumnHeader objects.
    ColumnHeader header1, header2;
    header1 = new ColumnHeader();
    header2 = new ColumnHeader();
    // Set the text, alignment and width for each column header.
    header1.set_Text("File name");
    header1.set_TextAlign(HorizontalAlignment.Left);
    header1.set_Width(70);

    header2.set_TextAlign(HorizontalAlignment.Left);
    header2.set_Text("Location");
    header2.set_Width(200);
    // Add the headers to the ListView control.
    listView1.get_Columns().Add(header1);
    listView1.get_Columns().Add(header2);
    // Populate the ListView.Items property.
    // Set the directory to the sample picture directory.
    System.IO.DirectoryInfo dirInfo =
        new System.IO.DirectoryInfo("C:\\Documents and Settings\\All Users"
        + "\\Documents\\My Pictures\\Sample Pictures");
    // Get the.jpg files from the directory
    System.IO.FileInfo files[] = dirInfo.GetFiles("*.jpg");
    // Add each file name and full name including path
    // to the ListView.
    if (files != null) {
        for (int iCtr = 0; iCtr < files.length; iCtr++) {
            System.IO.FileInfo file = files[iCtr];
            ListViewItem item = new ListViewItem(file.get_Name());
            item.get_SubItems().Add(file.get_FullName());
            listView1.get_Items().Add(item);
        }
    }
} //PopulateListView


Todos los miembros static (Shared en Visual Basic) públicos de este tipo son seguros para la ejecución de subprocesos. No se garantiza que los miembros de instancias sean seguros para la ejecución de subprocesos.

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

.NET Framework y .NET Compact Framework no admiten todas las versiones de cada plataforma. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.

.NET Framework

Compatible con: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Compatible con: 3.5, 2.0, 1.0
¿Le ha resultado útil?
(Caracteres restantes: 1500)
Contenido de la comunidad Agregar