Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid Checkbox?

Status
Not open for further replies.

jgoodman00

Programmer
Jan 23, 2001
1,510
I have a datagrid which connects to an MSAccess table. This table contains a number of columns which I want represented by a checkbox.

I initially set the datatype to Yes/No.

When I load the application the text-boxes default to Null even though Null is not allowed, & being a Yes/No field Null is impossible to get. Furtermore, if I try changing the value to either Yes or No (i.e. 1 or 0) I get another error saying 'DataType Mismatch'.

I then changed the underlying datatype to an Integer, & tried again. Same error.


How can I get the default value to be false, & the checkboxes to work?
What data-type should the underlying fields be?

James Goodman MCSE, MCDBA
 
Have looked all over but they wont work.
I have fields within my table which are set to yes/no.
This is the code I use to generate the checkbox:
Private Const TRUE_VAL = -1
Private Const FALSE_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

However, no matter what I do the checkbox is always set to tri-state (null). If I change the value to either true or false, the moment I navigate from the field it changes back to tri-state null...

James Goodman MCSE, MCDBA
 
Hi James
what i can guess as i don't have full code of yours is that
sometime it happens that check-box won't behave as it should be
In my case i get the solution by making a temporarty table with UnboundCol and return this table back to the Grid in my Stored Procedure..the problem for this is that Grid wants to have a read-write datatabe to update its contants and you can get the read-write by the following method
like

CREATE TABLE [dbo].[#TEMP_ABI_PROCESS]
(
[UnboundCol][bit],
[CEC_ID][char](10),
[CEC_SH_ID][char](10),
[CEC_EntryNo] [varchar] (8) ,
[CEC_ChkDgt][varchar](1),
[CEC_FileNo] [varchar](15),
[CEC_Process][varchar](10),
[CEC_TypeCode][varchar](5),
[SCDC_Desc][varchar](60),
[Status][varchar](60),
[SCC_PortEntry_ID][char](10),
[CEC_SecNo][varchar](5)
)
and the issue

INSERT INTO [dbo].[#TEMP_ABI_PROCESS]
Select * from sometable

tell me if this can help you out
Regards
Nouman

Nouman Zaheer
Software Engineer
MSR
 
Ok, I have now gotten to checkboxes to work (i.e. True/False only), but am having another problem.

When I attempt to update the data-adapter I get an error stating 'DataType mismatch in criteria expression'.

I examined the checkboxes, & they are behaving as expected; they are passing either True or False (both boolean datatype). However, I think this is now a conflict between the Access Yes/No datatype & the .Net Boolean datatype. I have seen something similar before when migrating from Access to SQL Server.




James Goodman MCSE, MCDBA
 
Hi James
May be thats the case but in your case you can update the underlying table by sending SQL query with parameters..in access you can make an update query with all the parameters and then you can execute that query from .Net
Regards
Nouman

Nouman Zaheer
Software Engineer
MSR
 
Hi jgoodman00
I just womder how you solved the problem with the tri-state checkboxes. We have the same problem. We have a SQL table which we get data from we place the data in a dataset and binds it to a datagrid. We use the DataGridBoolColumn object to get the checkboxes. The value for that column is -1 or 0. So we would like to use these as TrueValue and FalseValue but we get the same effect you did. Initially Null Value(grayed checkbox:checked). When we change the value to checked or unchecked then it reverts back to Null value. So how did you solve it ??
 
I did eventually solve this. I dont have a copy of .net infront of me at the moment, so this is from memory:


I found the problem was in the configuration of the dataadapter. When you add a dataset & datadapters, .net creates an xsd(?) file. If you open it you can see all of the table objects configured for your connection, & create relationships etc.
Unfortunately, it doesnt look like .net parses the default values, so you have to manually edit the default value for the columns you are interested in. I was using Access, so had to set the default to False, but for SQL Server it will need to be 0 (which you have said).

Let me know if this makes sense. If not I can give a more accurate step-by-step guide on monday...

James Goodman MCSE, MCDBA
 
Hi again,

I think the Step-by-step should be welcome here. We are currently trying this solution on a C#.NET solution without the complete VS.NET. So we can't use typed datasets. We have tried to create a DataGridBoolColumn and set FalseValue=0 and TrueValue=-1. But that doesn't help. Still grayed.

Magnus Müller
 
Well I'm back again,

I have found out how to do it myself.


You have to typecast the values which you want to set the TrueValue and FalseValue properties to. Such as...

TrueValue = (short) -1;
FalseValue = (short) 0;

Now our application works just fine.

/Magnus
 
Glad you solved it.

I found this area a little cumbersome, as you have to set the true & false value in more than one place, which can lead to problems.

Because I am using a lot of Checkboxes within my grids, I created two constants in the declarations section which are then applied to all checkboxes...

James Goodman MCSE, MCDBA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top