DataGrid with checkboxes

  • Thread starter Thread starter Jerry
  • Start date Start date
J

Jerry

I need to use the DataGrid control to display rows from a SQL table and also
show a checkbox that the user can click on to select different rows. I add a
Boolean DataColumn to the table and then assign it to the datagrid. I can
click on the checkbox and change the value, but when I click on another row
it errors out with that the column is read-only and asks if I want to
correct it. It won't let me change the value. If I use the SQL statement to
add the column as a constant of datatype 'bit' and a value of -1 then it
errors out with an invalid typecast error.

Here is the code where I create a new Boolean DataColumn and add it to the
table. This should be standard stuff, but I can't get anything to work. Any
suggestions?

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

SQL = "SELECT * FROM tblAnimalFacility";

DataColumn dc = new DataColumn("PrintCard",
System.Type.GetType("System.Boolean"),"-1");

ds =
Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteDataset(CommandType.Text,S
QL);

ds.Tables[0].Columns.Add(dc);

grdPurchases.DataSource = ds.Tables[0];
 
Hi Jerry,

Currently I am looking for somebody who could help you on it. We will reply
here with more information as soon as possible.
If you have any more concerns on it, please feel free to post here.


Thanks!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
Hi Jerry,

Thanks for your quickly reply!

From the MSDN we know that
A computed column, though, is permanently marked as read-only. In other
words, you cannot remove the readonly attribute for the column until the
bound expression is removed. Of course, the readonly attribute also
prevents any application to assign direct values to the cells of the column.

Express Yourself with Expression-based Columns
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndive/html
/data05312002.asp

That is to say when you define the Datacolumn as below.
DataColumn dc = new DataColumn("PrintCard",
System.Type.GetType("System.Boolean"),"-1");

the dc will be readonly.

while if defined in such way,
DataColumn dc = new DataColumn("PrintCard",
System.Type.GetType("System.Boolean"));

you can change the dc in run time.

If you still have any concern on this issue, please post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top