By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,515 Members | 1,061 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,515 IT Pros & Developers. It's quick & easy.

DataGridBoolColumn?

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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").Defa ultValue = 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

--------------------

"James Goodman" <j a m e s@norton-associates.co.u k> wrote in message
news:bu**********@hercules.btinternet.com...
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

Nov 20 '05 #2

P: n/a
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
Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.