Programmatically binding datagrid

  • Thread starter Niclas Lindblom
  • Start date
N

Niclas Lindblom

Hi,

I have a datagrid that contains a checkbox template column. I have followed
the sample in Q306227, but I have a problem evaluating the content of the
datagrid columns to decide a value for the checkboxes check property.

According to the sample I should use this statement in the BindCheckbox
event to evaluate a column:

Public Sub BindCheckBox(ByVal sender As Object, ByVal e As EventArgs)
'Create a new instance of a CheckBox.
Dim oCheckBox As CheckBox = CType(sender, CheckBox)
Dim container As DataGridItem = CType(oCheckBox.NamingContainer,
DataGridItem)
'Evaluate the data from the Grid item and set the Checked property
' appropriatly
If container.DataItem("contract").GetType.ToString = "System.DBNull"
Then
oCheckBox.Checked = False
Else
oCheckBox.Checked = CBool(container.DataItem("contract"))
End If

End Sub


The problem here is that my project is configured to use "Option Strict" and
does therefore not allow the statement

If container.DataItem("contract").GetType.ToString = "System.DBNull" Then

I tried to use Container.cells(2).text instead, but this only returns a
empty string in all rows.

Any suggestions on how to to do this ?

Regards

Niclas
 
G

Guest

Hi, Niclas

Why not try
If IsDBNull(container.DataItem("contract")) The
oCheckBox.Checked = Fals
Els
oCheckBox.Checked = CBool(container.DataItem("contract")
End I

Bin Song, MC

----- Niclas Lindblom wrote: ----

Hi

I have a datagrid that contains a checkbox template column. I have followed
the sample in Q306227, but I have a problem evaluating the content of the
datagrid columns to decide a value for the checkboxes check property

According to the sample I should use this statement in the BindCheckbox
event to evaluate a column

Public Sub BindCheckBox(ByVal sender As Object, ByVal e As EventArgs
'Create a new instance of a CheckBox
Dim oCheckBox As CheckBox = CType(sender, CheckBox
Dim container As DataGridItem = CType(oCheckBox.NamingContainer,
DataGridItem
'Evaluate the data from the Grid item and set the Checked propert
' appropriatl
If container.DataItem("contract").GetType.ToString = "System.DBNull"
The
oCheckBox.Checked = Fals
Els
oCheckBox.Checked = CBool(container.DataItem("contract")
End I

End Su


The problem here is that my project is configured to use "Option Strict" and
does therefore not allow the statemen

If container.DataItem("contract").GetType.ToString = "System.DBNull" The

I tried to use Container.cells(2).text instead, but this only returns a
empty string in all rows

Any suggestions on how to to do this

Regard

Niclas
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top