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