New to Telerik UI for WPF? Download free 30-day trial

Headers

RadVirtualGrid has Header elements for both its rows and columns. A more detailed look over the visual elements of the control can be found in the Styling and Appearance topic. The API of the control provides the HeaderValueNeeded and HeaderSizeNeeded events for setting the values and size of its headers. The properties that the event arguments expose are listed below.

HeaderValueNeeded

If the default DataProvider is used for populating the control with data, it handles the HeaderValueNeeded event. In order the default behavior to be altered, a Custom Data Provider can be utilized.

  • HeaderOrientation: Enumeration which has two values: Horizontal and Vertical. If the HeaderOrientation is Horizontal, the event is thrown for a Row Header, whereas if it is Vertical, it is thrown for a Column Header.

  • Index: Provides information regarding the index of the Header.

  • Value: The actual value to be applied to the Header.

HeaderSizeNeeded

  • HeaderOrientation: Enumeration similar to the one provided from the event arguments of the HeaderValueNeeded event.

  • Index: Provides information regarding the index of the Header.

  • Size: Sets the width or height of the header depending on the value of the HeaderOrientation property.

  • SizeUnit: An enumeration that provides two values - Pixel and Star. The first one sets a precise pixel size, whereas the second one applies a relative size for the header.

Example 1: Handling the HeaderSizeNeededEvent

private void VirtualGrid_HeaderSizeNeeded(object sender, Telerik.Windows.Controls.VirtualGrid.HeaderSizeEventArgs e) 
    { 
        if (e.HeaderOrientation == Telerik.Windows.Controls.VirtualGrid.VirtualGridOrientation.Horizontal) 
        { 
            if (e.Index % 2 == 0) 
            { 
                e.SizeUnit = Telerik.Windows.Controls.VirtualGrid.HeaderSizeUnit.Star; 
            } 
            else 
            { 
                e.Size = 130; 
            } 
        } 
    } 

Figure 1: RadVirtualGrid with custom size for the headers

RadVirtualGrid with custom size for the headers

To learn how to conditionally style the cells (including the header cells), you can read the Conditional Styling.

See Also

In this article