GridView Class

 

Represents a view mode that displays data items in columns for a ListView control.

Namespace:   System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)


[StyleTypedPropertyAttribute(Property = "ColumnHeaderContainerStyle", 
	StyleTargetType = (GridViewColumnHeader^::typeid))]
[ContentPropertyAttribute("Columns")]
public ref class GridView : ViewBase, IAddChild

NameDescription
System_CAPS_pubmethodGridView()

Initializes a new instance of the GridView class.

NameDescription
System_CAPS_pubpropertyAllowsColumnReorder

Gets or sets whether columns in a GridView can be reordered by a drag-and-drop operation.

System_CAPS_pubpropertyColumnHeaderContainerStyle

Gets or sets the style to apply to column headers.

System_CAPS_pubpropertyColumnHeaderContextMenu

Gets or sets a ContextMenu for the GridView.

System_CAPS_pubpropertyColumnHeaderStringFormat

Gets or sets a composite string that specifies how to format the column headers of the GridView if they are displayed as strings.

System_CAPS_pubpropertyColumnHeaderTemplate

Gets or sets a template to use to display the column headers.

System_CAPS_pubpropertyColumnHeaderTemplateSelector

Gets or sets the selector object that provides logic for selecting a template to use for each column header.

System_CAPS_pubpropertyColumnHeaderToolTip

Gets or sets the content of a tooltip that appears when the mouse pointer pauses over one of the column headers.

System_CAPS_pubpropertyColumns

Gets the collection of GridViewColumn objects that is defined for this GridView.

System_CAPS_protpropertyDefaultStyleKey

Gets the reference for the default style for the GridView.(Overrides ViewBase::DefaultStyleKey.)

System_CAPS_pubpropertyDependencyObjectType

Gets the DependencyObjectType that wraps the CLR type of this instance. (Inherited from DependencyObject.)

System_CAPS_pubpropertyDispatcher

Gets the Dispatcher this DispatcherObject is associated with. (Inherited from DispatcherObject.)

System_CAPS_pubpropertySystem_CAPS_staticGridViewItemContainerStyleKey

Gets the key that references the style that is defined for each ListViewItem in a GridView.

System_CAPS_pubpropertySystem_CAPS_staticGridViewScrollViewerStyleKey

Gets the key that references the style that is defined for the ScrollViewer control that encloses the content that is displayed by a GridView.

System_CAPS_pubpropertySystem_CAPS_staticGridViewStyleKey

Gets the key that references the style that is defined for the GridView.

System_CAPS_pubpropertyIsSealed

Gets a value that indicates whether this instance is currently sealed (read-only).(Inherited from DependencyObject.)

System_CAPS_protpropertyItemContainerDefaultStyleKey

Gets the reference to the default style for the container of the data items in the GridView.(Overrides ViewBase::ItemContainerDefaultStyleKey.)

NameDescription
System_CAPS_pubpropertySystem_CAPS_staticColumnCollection

Gets or sets the attached property that contains the GridViewColumnCollection.

NameDescription
System_CAPS_protmethodAddChild(Object^)

This API supports the product infrastructure and is not intended to be used directly from your code. Adds a GridViewColumn object to a GridView.

System_CAPS_protmethodAddText(String^)

This API supports the product infrastructure and is not intended to be used directly from your code. Not supported.

System_CAPS_pubmethodCheckAccess()

Determines whether the calling thread has access to this DispatcherObject.(Inherited from DispatcherObject.)

System_CAPS_protmethodClearItem(ListViewItem^)

Removes all settings, bindings, and styling from a ListViewItem.(Overrides ViewBase::ClearItem(ListViewItem^).)

System_CAPS_pubmethodClearValue(DependencyProperty^)

Clears the local value of a property. The property to be cleared is specified by a DependencyProperty identifier. (Inherited from DependencyObject.)

System_CAPS_pubmethodClearValue(DependencyPropertyKey^)

Clears the local value of a read-only property. The property to be cleared is specified by a DependencyPropertyKey. (Inherited from DependencyObject.)

System_CAPS_pubmethodCoerceValue(DependencyProperty^)

Coerces the value of the specified dependency property. This is accomplished by invoking any CoerceValueCallback function specified in property metadata for the dependency property as it exists on the calling DependencyObject.(Inherited from DependencyObject.)

System_CAPS_pubmethodEquals(Object^)

Determines whether a provided DependencyObject is equivalent to the current DependencyObject.(Inherited from DependencyObject.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_protmethodGetAutomationPeer(ListView^)

Gets the AutomationPeer implementation for this GridView object.(Overrides ViewBase::GetAutomationPeer(ListView^).)

System_CAPS_pubmethodSystem_CAPS_staticGetColumnCollection(DependencyObject^)

Gets the contents of the ColumnCollection attached property.

System_CAPS_pubmethodGetHashCode()

Gets a hash code for this DependencyObject.(Inherited from DependencyObject.)

System_CAPS_pubmethodGetLocalValueEnumerator()

Creates a specialized enumerator for determining which dependency properties have locally set values on this DependencyObject. (Inherited from DependencyObject.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodGetValue(DependencyProperty^)

Returns the current effective value of a dependency property on this instance of a DependencyObject. (Inherited from DependencyObject.)

System_CAPS_pubmethodInvalidateProperty(DependencyProperty^)

Re-evaluates the effective value for the specified dependency property(Inherited from DependencyObject.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_protmethodOnPropertyChanged(DependencyPropertyChangedEventArgs)

Invoked whenever the effective value of any dependency property on this DependencyObject has been updated. The specific dependency property that changed is reported in the event data. (Inherited from DependencyObject.)

System_CAPS_protmethodPrepareItem(ListViewItem^)

Prepares a ListViewItem for display according to the definition of this GridView object.(Overrides ViewBase::PrepareItem(ListViewItem^).)

System_CAPS_pubmethodReadLocalValue(DependencyProperty^)

Returns the local value of a dependency property, if it exists. (Inherited from DependencyObject.)

System_CAPS_pubmethodSystem_CAPS_staticSetColumnCollection(DependencyObject^, GridViewColumnCollection^)

Sets the contents of the ColumnCollection attached property.

System_CAPS_pubmethodSetCurrentValue(DependencyProperty^, Object^)

Sets the value of a dependency property without changing its value source. (Inherited from DependencyObject.)

System_CAPS_pubmethodSetValue(DependencyProperty^, Object^)

Sets the local value of a dependency property, specified by its dependency property identifier. (Inherited from DependencyObject.)

System_CAPS_pubmethodSetValue(DependencyPropertyKey^, Object^)

Sets the local value of a read-only dependency property, specified by the DependencyPropertyKey identifier of the dependency property. (Inherited from DependencyObject.)

System_CAPS_pubmethodSystem_CAPS_staticShouldSerializeColumnCollection(DependencyObject^)

Determines whether to serialize the ColumnCollection attached property.

System_CAPS_protmethodShouldSerializeProperty(DependencyProperty^)

Returns a value that indicates whether serialization processes should serialize the value for the provided dependency property.(Inherited from DependencyObject.)

System_CAPS_pubmethodToString()

Returns the string representation of the GridView object.(Overrides Object::ToString().)

System_CAPS_pubmethodVerifyAccess()

Enforces that the calling thread has access to this DispatcherObject.(Inherited from DispatcherObject.)

NameDescription
System_CAPS_pubfieldSystem_CAPS_staticAllowsColumnReorderProperty

Identifies the AllowsColumnReorder dependency property.

System_CAPS_pubfieldSystem_CAPS_staticColumnCollectionProperty

Identifies the ColumnCollectionProperty attachedproperty.

System_CAPS_pubfieldSystem_CAPS_staticColumnHeaderContainerStyleProperty

Identifies the ColumnHeaderContainerStyle dependency property.

System_CAPS_pubfieldSystem_CAPS_staticColumnHeaderContextMenuProperty

Identifies the ColumnHeaderContextMenu dependency property.

System_CAPS_pubfieldSystem_CAPS_staticColumnHeaderStringFormatProperty

Identifies the ColumnHeaderStringFormat dependency property.

System_CAPS_pubfieldSystem_CAPS_staticColumnHeaderTemplateProperty

Identifies the ColumnHeaderTemplate dependency property.

System_CAPS_pubfieldSystem_CAPS_staticColumnHeaderTemplateSelectorProperty

Identifies the ColumnHeaderTemplateSelector dependency property.

System_CAPS_pubfieldSystem_CAPS_staticColumnHeaderToolTipProperty

Identifies the ColumnHeaderToolTip dependency property.

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodIAddChild::AddChild(Object^)

This API supports the product infrastructure and is not intended to be used directly from your code. Adds a child object.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIAddChild::AddText(String^)

This API supports the product infrastructure and is not intended to be used directly from your code. Adds the text content of a node to the object.

The GridView class and its supporting classes provide the infrastructure to display data items that are specified for a ListView control in a series of columns. The columns have column headers, which are buttons that are derived from ButtonBase, and you can reorder the columns by using drag-and-drop operations. Note that the columns of a GridView display data and do not provide direct access to the source of the data.

To specify a GridView as the view mode for a ListView, set the View property to a GridView object.

The GridView class is derived from ViewBase. You can define custom views by inheriting from the ViewBase class that provides the supporting elements for a view. For more information, see How to: Create a Custom View Mode for a ListView.

The following illustration shows an example of a ListView that uses a GridView.

ListView with GridView output

The columns in a GridView are defined as GridViewColumn objects. In Extensible Application Markup Language (XAML), you can define GridViewColumn objects as child elements of the GridView. In code, you can add a GridViewColumn to the GridView by using the Columns property and the Add method that is defined for the Collection<T> class. Similarly, you can use other Collection<T> methods such as Remove and Insert to modify the columns in a GridView.

The following example shows how to define the columns of a GridView.

No code example is currently available or this language may not be supported.

<GridView AllowsColumnReorder="true"
          ColumnHeaderToolTip="Employee Information">

  <GridViewColumn DisplayMemberBinding=
                      "{Binding Path=FirstName}" 
                  Header="First Name" Width="100"/>

              <GridViewColumn DisplayMemberBinding=
                      "{Binding Path=LastName}" 
                  Width="100">
                  <GridViewColumnHeader>Last Name
                      <GridViewColumnHeader.ContextMenu>
                      <ContextMenu  MenuItem.Click="LastNameCM_Click"  
                                    Name="LastNameCM">
                          <MenuItem Header="Ascending" />
                          <MenuItem Header="Descending" />
                      </ContextMenu>
                      </GridViewColumnHeader.ContextMenu>
                  </GridViewColumnHeader>
              </GridViewColumn>

              <GridViewColumn DisplayMemberBinding=
                      "{Binding Path=EmployeeNumber}" 
                  Header="Employee No." Width="100"/>
</GridView>

To style the rows in a GridView, define a style for the ListViewItem controls in the ListView.

To add visual elements, such as a CheckBox or Button control, to a GridView, use templates or styles. For an example, see How to: Create ListViewItems with a CheckBox.

The following example shows how to define a ListView control that implements a GridView as its View.

  <ListView ItemsSource="{Binding Source={StaticResource EmployeeData}, 
                         XPath=Employee}">
  <ListView.View>
    <GridView>
      <GridViewColumn Header="First Name" 
                      DisplayMemberBinding="{Binding XPath=FirstName}" />
      <GridViewColumn Header="Last Name" 
                      DisplayMemberBinding="{Binding XPath=LastName}" />
      <GridViewColumn Header="Favorite City"
                      DisplayMemberBinding="{Binding XPath=FavoriteCity}"/>
    </GridView>
  </ListView.View>
</ListView>

.NET Framework
Available since 3.0

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: