In various cases you may want to access or traverse grid functional items/columns outside the dedicated ItemCreated and ItemDataBound event handlers, for example during PreRender or DataBinding event handlers of the grid. This is easily attainable with the GetItems(itemType), GetColumn(columnName) and GetColumnSafe(columnName) methods (exposed by each GridTableView instance).

Protected Sub RadGrid1_PreRender(sender As Object, e As EventArgs)
For Each item As GridDataItem In RadGrid1.Items
If item.ItemIndex Mod 3 = 0 Then
item("ShipName").BackColor = System.Drawing.Color.Orange
End If
Next
End Sub

Protected Sub RadGrid1_PreRender(sender As Object, e As EventArgs)
For Each item As GridDataItem In RadGrid1.EditItems
' InPlace EditMode
Dim textBox1 As TextBox = TryCast(item("ShipName").Controls(0), TextBox)
' EditForms and PopUp EditMode
Dim editFormItem As GridEditFormItem = item.EditFormItem
If editFormItem.IsInEditMode Then
Dim textBox2 As TextBox = TryCast(editFormItem("ShipName").Controls(0), TextBox)
End If
Next
' alternative approach
For Each item As GridEditFormItem In RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem)
If item.IsInEditMode Then
Dim textBox3 As TextBox = TryCast(item("ShipName").Controls(0), TextBox)
End If
Next
End Sub

Protected Sub RadGrid1_PreRender(sender As Object, e As EventArgs)
If RadGrid1.MasterTableView.IsItemInserted Then
' GridEditFormInsertItem for EditForms and PopUp EditMode
' GridDataInsertItem for InPlace EditMode
Dim insertItem As GridEditableItem = RadGrid1.MasterTableView.GetInsertItem()
End If
End Sub

The GetColumn(columnName) method returns the column with the unique name specified as argument, namely:

GridColumn column = RadGrid1.MasterTableView.GetColumn("OrderID");
//thus you get reference to the column with OrderID unique name

Dim column As GridColumn = RadGrid1.MasterTableView.GetColumn("OrderID")
'thus you get reference to the column with OrderID unique name

The GetColumnSafe(columnName) performs the same task as GetColumn(columnName) method, however GetColumnSafe will not raise an exception in case column with that name is not found in the corresponding GridTableView.

The entire column collection can be traversed using the following approach:

Protected Sub RadGrid1_DataBinding(sender As Object, e As EventArgs)
For Each col As GridColumn In RadGrid1.MasterTableView.RenderColumns
If col.DataType = GetType(Decimal) Then
TryCast(col, IGridDataColumn).AllowFiltering = False
End If
If TypeOf col Is GridDateTimeColumn Then
Dim dateCol As GridDateTimeColumn = DirectCast(col, GridDateTimeColumn)
dateCol.DataFormatString = "{0:d}"
End If
Next
End Sub

The forthcoming sample implementation is made for hierarchical grid with two levels. With separate buttons on the page you can:

Give article feedback

Tell us how we can improve this article

Code samples are inaccurate/outdated.
I expected to find other/more information.
There are typos/broken links/broken page elements.
Content is inaccurate/outdated.
Other
By checking this box you consent to Progress contacting you by email about your response on this page.