CheckBox in a DataGrid

R

Randy

Hello,
I'm creating a table on the fly that is used by a datagrid. I'm also
creating a tableStyle that is used for the datagrid to make it look like I
want.
I'm using the DataGridBoolColumn to make one column a CheckBox field. It
shows up fine...as a CheckBox. I looped through the table and stored a true
or false in the checkbox column but it appears to have no effect on the
checkbox column. No matter what I store there (true/false), when I run the
app all the checkboxes are checked/greyed. I thought I could store a true or
false in this column of the table and it would either be checked or
unchecked in the CheckBox...but that doesn't seem to work. Am I going about
it wrong?
Any help would be appreciated...
Thanks
 
I

idog

Public Class DynamicItemTemplate

' ITemplate - When implemented by a class, defines the Control object

' to which child controls and templates belong. These child controls

' are in turn defined within an inline template.

Implements ITemplate

Public Overridable Overloads Sub InstantiateIn(ByVal container As Control)
Implements ITemplate.InstantiateIn

' InstantiateIn - When implemented by a class, defines the Control

' object to which child controls and templates belong. These child

' controls are, in turn, defined within an inline template.

'

' Create an instance of a CheckBox object.

Dim oCheckBox As CheckBox = New CheckBox

' When the DataBinding event of the CheckBox fires, call the sub

' BindCheckBox to properly bind.

AddHandler oCheckBox.DataBinding, AddressOf BindCheckBox

'Add the CheckBox to the controls collection.

oCheckBox.Enabled = False

container.Controls.Add(oCheckBox)

End Sub



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("fCurrent").GetType.ToString = "System.DBNull" Then

oCheckBox.Checked = False

Else

oCheckBox.Checked = CBool(container.DataItem("fCurrent"))

End If

End Sub
 
R

Randy

Thanks for the info idog...but I'm still kind of in the dark on this. I
can't really tell what you're doing here in this code...
 

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

Top