DataGrid Sample - Changing Binding Information At Runtime

M

Mythran

I have seen many examples on the Internet that do the following to format
data being bound to a DataGrid....IMO, it's sick..

Public Sub MyGrid_ItemDataBound( ... )
Dim value As String = e.Item.Cells(0).Text.ToLower()
If value = "true"
e.Item.Cells(0).Text = "Yes"
Else
e.Item.Cells(0).Text = "No"
End If
End Sub


Why would people use this instead of accessing the data row directly?

Public Sub MyGrid_ItemDataBound( ... )
Dim value As Boolean = e.Item.DataItem.Row.MyBooleanValue
e.Item.Cells(0).Text = IIf(value, "Yes", "No")
End Sub

IMO, it's easier and safer than using the TEXT value of the cell to get at
the data ... am I safe in assuming this?

We actually created another DataGrid (derived from DataGrid) that goes even
further by adding methods to retreive the cell of the data grid for the item
being bound (GetItemCell(DataGridItem, ColumnHeaderText)) to get the cell,
rather than accessing the cell ordinally. May take longer because it loops
to find the column ordinal with the specific ColumnHeaderText, but on MOST
if not ALL DataGrids, there are only a few columns of data...so the loop is
insignificant.

Thanks,
Mythran
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,076
Latest member
OrderKetoBeez

Latest Threads

Top