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

P

PeterZ

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
 
D

Dmitriy Lapshin [C# / .NET MVP]

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.
 
P

PeterZ

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
 

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