Imports Infragistics.Win
Imports Infragistics.Win.UltraWinGrid
' クラスで IUIElementCreationFilter インターフェイスを実装
' (この事例ではフォーム)
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
' IUIElementCreationFilter インターフェイスを実装するオブジェクトに
' グリッドのCreationFilter プロパティを設定
Me.UltraGrid1.CreationFilter = Me
End Sub
Public Function BeforeCreateChildElements( _
ByVal parent As Infragistics.Win.UIElement) _
As Boolean Implements _
Infragistics.Win.IUIElementCreationFilter.BeforeCreateChildElements
' false を返します。これによりデフォルトの子要素作成を行うために
' PositionChildElements が呼び出されます
Return False
End Function
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 (Not (TypeOf (parent) Is CellUIElement)) Then Return
' 関連付けられた列を取得します
column = parent.GetContext(GetType(UltraGridColumn))
' 列がボタンを追加しようとしている列でない場合は戻ります。
If column Is Nothing Then Return
If Not column.Key = "City" Then Return
' 新しいボタン 要素を作成します。
elementToAdd = New ButtonUIElement(parent)
' ボタン 要素のクリック イベントをフックします。
AddHandler elementToAdd.ElementClick, AddressOf Me.OnCustomButtonClick
' ボタン 要素の境界線内部にある親要素の四角形を取得します。
rc = parent.RectInsideBorders
' ボタンの四角形の幅を設定します。
rc.Width = 12
' ボタン 要素の四角形を設定します。
elementToAdd.Rect = rc
' 子要素をループし、矩形を調整します。
' これによってボタンを重複しません
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
' ボタン要素を子要素コレクション
' に加えます
parent.ChildElements.Add(elementToAdd)
End Sub
Private Sub OnCustomButtonClick(ByVal sender As System.Object, _
ByVal e As UIElementEventArgs)
Dim cell As UltraGridCell
' 関連付けられたセルを取得します。
cell = e.Element.GetContext(GetType(UltraGridCell))
' セルのテキストを表示するなどの操作を実行します。
If (Not cell Is Nothing) Then
MessageBox.Show( _
"Custom cell button clicked. Cell.Text = " + cell.Text)
End If
End Sub