471,123 Members | 850 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,123 software developers and data experts.

DataGridBoolColumn, checkbox, numeric values - can it be done?

Hi,

In the past I've successfully databound a conventional Winforms checkbox to
a number column in an Oracle table, where 1 represents true and 0 represents
false. The checkbox would be ticked if the value was 1 and unticked if the
value was 0 - earth shattering news I know! :-)

HOWEVER......

I tried doing the same thing but in a datagrid with one of the columns as a
DataGridBoolColumn - basically it doesn't work! The checkbox in the
datagrid is ALWAYS grey-checked regardles of the underlying value.

In the IDE I've set:

TrueValue to 1
FalseValue to 0
AllowNulls to false
I thought this was supposed to be a no-brainer???

So, is it possible to use DataGridBoolColumn with an underlying numeric
column? Any samples, links, etc. greatly appreciated 'cause I'm stuck with
this.

Cheers,
PeterZ
Nov 16 '05 #1
2 2073
Hi,

There might be a simplier solution, but here goes:

a) Create a column derived from DataGridBoolColumn
b) Override the GetColumnValueAtRow (and SetColumnValueAtRow if you want
your column to be editable)
c) Make these methods call the inherited implementations to work with the
datasource, but do some pre-/post-processing to convert 0 and 1 to "false"
and "true" respectively.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"PeterZ" <_R**********************@hotmail.com> wrote in message
news:40***********************@news.optusnet.com.a u...
Hi,

In the past I've successfully databound a conventional Winforms checkbox to a number column in an Oracle table, where 1 represents true and 0 represents false. The checkbox would be ticked if the value was 1 and unticked if the value was 0 - earth shattering news I know! :-)

HOWEVER......

I tried doing the same thing but in a datagrid with one of the columns as a DataGridBoolColumn - basically it doesn't work! The checkbox in the
datagrid is ALWAYS grey-checked regardles of the underlying value.

In the IDE I've set:

TrueValue to 1
FalseValue to 0
AllowNulls to false
I thought this was supposed to be a no-brainer???

So, is it possible to use DataGridBoolColumn with an underlying numeric
column? Any samples, links, etc. greatly appreciated 'cause I'm stuck with this.

Cheers,
PeterZ


Nov 16 '05 #2
Hi Dmitriy,

Tried your suggestion but still had the grey-checked boxes. At least
I learned something about what happens under the hood of
DataGridBoolColumn.

After investigating things further it appears the problem lies with
the Oracle datatype - Oracle NUMERIC type maps to .NET DECIMAL type,
and from what I can tell DataGridBoolColumn doesn't like that, it
needs a BOOL or an INT!

Easily fixed if you have a strongly typed dataset - I opened up the
dataset schema (XSD file) and changed the column's type from DECIMAL
to INT in the dropdown.

Now everything is working fine, I'm using just the standard
implementation of DataGridBoolColumn and values get written to the DB
as 1 or 0 as expected.

Cheers,
PeterZ
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote in message news:<ue**************@TK2MSFTNGP12.phx.gbl>...
Hi,

There might be a simplier solution, but here goes:

a) Create a column derived from DataGridBoolColumn
b) Override the GetColumnValueAtRow (and SetColumnValueAtRow if you want
your column to be editable)
c) Make these methods call the inherited implementations to work with the
datasource, but do some pre-/post-processing to convert 0 and 1 to "false"
and "true" respectively.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by subT | last post: by
4 posts views Thread by Ubi | last post: by
2 posts views Thread by nate axtell | last post: by
1 post views Thread by B.J. Raiford | last post: by
2 posts views Thread by NetRacer | last post: by
reply views Thread by Ryan Liu | last post: by
2 posts views Thread by Jason Huang | last post: by
16 posts views Thread by Dwight | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.