473,388 Members | 1,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 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 2133
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: subT | last post by:
created several tablestyles, added columstyles..added datagridboolcolumn to one of the collections.. I dont have a problem with the required 2 clicks to change a checkbox value, however, on the...
4
by: Ubi | last post by:
Hi, my code is: myDataTBL.Columns.Add("checked",System.Type.GetType("System.Boolean")); DataGridBoolColumn cs1 = new DataGridBoolColumn(); cs1.NullValue=false; cs1.TrueValue=true;...
1
by: Edward Koucherian | last post by:
I'm getting the incorrect display value on my DataGrid column. The field is numeric (1) in the SQL database table The Code is txtCol = New DataGridBoolColumn txtCol.MappingName = "MyCol"...
2
by: nate axtell | last post by:
I'm trying to create a custom DataGridBoolColumn. I inherit DataGridColumnStyle and create a public CheckBox variable. This columnType will be mapped to a dataTable boolean column. What are the...
1
by: B.J. Raiford | last post by:
I have a DataGrid on a form in my application that is bound to an xml file and I have set the table style to contain a few columns with one editable one, a DataGridBoolColumn. I set...
2
by: NetRacer | last post by:
hi, i have a DataGrid with a DataGridBoolColumn. The assigned Column is a TinyInt and the values are only 0 or 1. I set these values to the TrueValue und FalseValue Property, but the CheckBox...
0
by: Ryan Liu | last post by:
Hi, I have a strange problem, should be very simple, take me days I couldn't finger out. Really appreciate if you can help me fine the problem. I am trying to use DataGridBoolColumn, but I...
2
by: Jason Huang | last post by:
Hi, In VS2003, C# Windows form project, on my DataGrid1. The first column's style in my DataGrid1 is DataGridBoolColumn. When I first click that checkbox, the checkbox doesn't turn to checked,...
16
by: Dwight | last post by:
If a windows form checkbox control is checked, shouldn't the following equal 1 instead of -1 ? DIM Acndt_ind as integer Acndt_ind = CInt(chbAcndt_Ind.Checked) Thanks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.