DataGridBoolColumn?

J

James Goodman

I have a number of bool columns within a datagrid, but they dont work as
expected.

The underlying table is Access 2000. The datatype for the underlying fields
is Yes/No.

I am attempting to create DataGridBoolColumns using the following code:

Private Const TRUE_VAL = -1

Private Const FALSE_VAL = 0

Private Const NULL_VAL = 0



Me.dgdTimDatPlotChkForks = New DataGridBoolColumn()

Me.dgdTimDatPlotChkForks.HeaderText = "FORKS"

Me.dgdTimDatPlotChkForks.MappingName = "FORKS"

Me.dgdTimDatPlotChkForks.Width = 75

Me.dgdTimDatPlotChkForks.AllowNull = False

Me.dgdTimDatPlotChkForks.TrueValue = TRUE_VAL

Me.dgdTimDatPlotChkForks.FalseValue = FALSE_VAL

Me.dgdTimDatPlotChkForks.NullValue = NULL_VAL



I need my checkboxes to not allow null; they must be either true or false,
with a default value of false.

However, when the app is run, they are always tri-state null (greyed out), &
even if they are changed to either true/false, as soon as the user navigates
from the column it returns to null.

Any suggestions as to what is wrong?




--
Cheers,


James Goodman MCSE, MCDBA
http://www.angelfire.com/sports/f1pictures
 
K

Ken Tucker [MVP]

Hi,

Here is an example which uses the northwind database. I assume you
have imports system.data.oledb at the top of your code file.

Dim conn As OleDbConnection

Dim strConn As String

Dim strSQL As String

Dim da As OleDbDataAdapter

Dim ds As New DataSet

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"

strConn &= "Data Source = Northwind.mdb;"

conn = New OleDbConnection(strConn)

da = New OleDbDataAdapter("Select * From Products", conn)

da.Fill(ds, "Products")

ds.Tables("Products").Columns("Discontinued").DefaultValue = False

Dim ts As New DataGridTableStyle

ts.MappingName = ds.Tables("Products").TableName



Dim colDiscontinued As New DataGridBoolColumn

With colDiscontinued

..MappingName = "Discontinued"

..HeaderText = "Discontinued"

..Width = 80

End With

Dim colName As New DataGridTextBoxColumn

With colName

..MappingName = "ProductName"

..HeaderText = "Product Name"

..Width = 180

End With



ts.GridColumnStyles.Add(colName)

ts.GridColumnStyles.Add(colDiscontinued)

DataGrid1.TableStyles.Add(ts)

ts = Nothing

colDiscontinued = Nothing

colName = Nothing

DataGrid1.DataSource = ds.Tables("Products")



Ken
 
J

James Goodman

Ok, I have been looking at this.

I have managed to get the checkboxes to behave as they should (i.e.
true/false), but when I attempt to update the data-adapter I get a 'DataType
mismatch in criteria expression' error.

If I examine the value contained in the checkbox in question, its value will
be either True or False, as desired, so I dont think the problem is here.

I think the problem is a difference between a vb.net True value, & an Access
Yes/No True value.


Any ideas?

--
Cheers,


James Goodman MCSE, MCDBA
http://www.angelfire.com/sports/f1pictures
 

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