Version

CreationFilter Property (UltraControlBase)

Gets/sets the creation filter property
Syntax
'Declaration
 
Public Property CreationFilter As IUIElementCreationFilter
public IUIElementCreationFilter CreationFilter {get; set;}
Example

The following sample code illustrates how to add a button element to an UltraGrid cell.



Imports Infragistics.Win
    Imports Infragistics.Win.UltraWinGrid

' Implement the IUIElementCreationFilter interface on a class
' (in this case the form)
Public Class Form1
    Inherits System.Windows.Forms.Form
    Implements Infragistics.Win.IUIElementCreationFilter


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        ' Set the grid’s CreationFilter property to the object that
        ' implements the IUIElementCreationFilter interface.
        Me.UltraGrid1.CreationFilter = Me

    End Sub

    Public Sub AfterCreateChildElements(ByVal parent As Infragistics.Win.UIElement) Implements Infragistics.Win.IUIElementCreationFilter.AfterCreateChildElements

        Dim column As UltraGridColumn
        Dim child As UIElement
        Dim rc As Rectangle
        Dim childRect As Rectangle
        Dim elementToAdd As ButtonUIElement

        ' If the parent element is not a cell element return
        If (Not (TypeOf (parent) Is CellUIElement)) Then Return

        ' Get the associated column
        column = parent.GetContext(GetType(UltraGridColumn))

        ' Return if the column isn’t the one we want to add the button to.
        If column Is Nothing Then Return
        If Not column.Key = "City" Then Return

        ' Create a new button element
        elementToAdd = New ButtonUIElement(parent)

        ' hook into its click event
        AddHandler elementToAdd.ElementClick, AddressOf Me.OnCustomButtonClick

        ' Get the rect of the parent element inside its borders
        rc = parent.RectInsideBorders

        ' Set the width of the button's rect
        rc.Width = 12

        ' Set the button element's rect
        elementToAdd.Rect = rc

        ' Loop over the child elements and adjust their
        ' rects so they don't overlap the button
        For Each child In parent.ChildElements
            childRect = child.Rect

            If (childRect.Left < rc.Right) Then
                childRect.Width -= rc.Right - childRect.Left
                childRect.X += rc.Right - childRect.Left
                child.Rect = childRect
            End If
        Next

        ' Append the button element to the 
        ' child elements collection
        parent.ChildElements.Add(elementToAdd)

    End Sub

    Private Sub OnCustomButtonClick(ByVal sender As System.Object, ByVal e As UIElementEventArgs)

        Dim cell As UltraGridCell

        ' Get the associated cell
        cell = e.Element.GetContext(GetType(UltraGridCell))

        ' Display the cell's text or do something more meaningful
        If (Not cell Is Nothing) Then
            MessageBox.Show("Custom cell button clicked. Cell.Text = " + cell.Text)
        End If

    End Sub
using System.Diagnostics;
	using Infragistics.Win;
	using Infragistics.Win.UltraWinGrid;

// Implement the IUIElementCreationFilter interface on a class
// (in this case the form)
public class Form1 : 
		System.Windows.Forms.Form, 
		Infragistics.Win.IUIElementCreationFilter
{

	private void Form1_Load(object sender, System.EventArgs e)
	{

		// Set the grid’s CreationFilter property to the object that
		// implements the IUIElementCreationFilter interface.

		this.ultraGrid1.CreationFilter = this;

	}

	public void AfterCreateChildElements(Infragistics.Win.UIElement parent)
	{

		// See if the parent element is a cell element
		if ( parent is CellUIElement )
		{
			// Get the associated column
			UltraGridColumn column = parent.GetContext( typeof( UltraGridColumn ) ) as UltraGridColumn;

			// See if the column is the one we want to add the button to
			if ( column != null &&
				 column.Key == "City" )
			{
				// Create a new button element
				ButtonUIElement elementToAdd = new ButtonUIElement( parent );
				
				// Hook into its click event
				elementToAdd.ElementClick += new UIElementEventHandler( this.OnCustomButtonClick );
				
				// Get the rect of the parent element inside its borders
				Rectangle rect = parent.RectInsideBorders;

				// Set the width of the button's rect
				rect.Width = 12;

				// Set the button's rect
				elementToAdd.Rect = rect;

				// Loop over the child elements and adjust their
				// rects so they don't overlap the button
				foreach ( UIElement child in parent.ChildElements )
				{
					Rectangle childRect = child.Rect;

					if ( childRect.Left < rect.Right )
					{
						childRect.Width -= rect.Right - childRect.Left;
						childRect.X		+= rect.Right - childRect.Left;
						child.Rect = childRect;
					}
				}

				// Append the button element to the 
				// child elements collection
				parent.ChildElements.Add( elementToAdd );
			}
		}

	}

	public bool BeforeCreateChildElements(Infragistics.Win.UIElement parent)
	{

		return false;

	}

	private void OnCustomButtonClick( object sender, UIElementEventArgs e )
	{

		// Get the associated cell
		UltraGridCell cell = e.Element.GetContext( typeof( UltraGridCell ) ) as UltraGridCell;

		// Display the cell's text or do something more meaningful
		if ( cell != null )
			MessageBox.Show("Custom cell button clicked. Cell.Text = " + cell.Text);

	}
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also