Groups | Blog | Home
all groups > dotnet windows forms databinding > august 2004 >

dotnet windows forms databinding : datagridboolcolumn


David Lei
8/24/2004 5:30:45 PM
Hi,

I have a DataGrid with a DataGridBoolColumn(checkbox) column bind to a
DataSet,
mapping source type is a SQL bit data type. I want to save the
changes(checked or unchecked)
to the database.

My problem is the DataGridBoolColumn does not seem to save the "1" or "0"
value to
the DataSet. All other columns in the same DataGrid caused the
DataSet.HasChanges() to
return True, except the checkbox column.

Any ideas?

Thanks
David

David Lei
8/25/2004 9:33:48 AM
Thanks for your reply.

I guess my question is DataSet.HasChanges() always return False
when I check/uncheck the DataGridBoolColumn.

If DataGrid does not update the DataSet directly, How can I update it?

Thanks

[quoted text, click to view]

v-jetan NO[at]SPAM online.microsoft.com (
8/25/2004 9:50:05 AM
Hi David,

Based on my understanding, you can not updating bool column in dataset
through DataGrid.

I have writen a sample project, which retrieve the datatable through a
sample table in Sql Server's pubs database. This table contains a column
"bool" which can be updated well in datagrid:
private void button1_Click(object sender, System.EventArgs e)
{
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
Console.WriteLine(ds.Tables[0].Rows[i]["bool"].ToString());
}
}

DataSet ds=null;
private void Form1_Load(object sender, System.EventArgs e)
{
SqlDataAdapter adapter=new SqlDataAdapter("select * from b",
"server=localhost;database=pubs;uid=sa;pwd=test");
ds=new DataSet();
adapter.Fill(ds);
this.dataGrid1.DataSource=ds.Tables[0];
}

The table's sql script is:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[b]')
and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[b]
GO

CREATE TABLE [dbo].[b] (
[id] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[name] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[bool] [bit] NULL
) ON [PRIMARY]
GO

If I misunderstand you, please feel free to tell me.
==========================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
v-jetan NO[at]SPAM online.microsoft.com (
8/26/2004 1:46:32 AM
Hi David,

Thanks for your feedback.

Sorry, in my test sample, DataSet.HasChanges() method returns true after
unchecking/checking DataGridBoolColumn.

I guess that if your code calls DataSet.AcceptChanges() method? Normally,
we should not call this method, after calling this method, all the changes
in the dataset will become unchanged state, and DataSet.HasChanges() method
will return false from then on.

Also, if the problem still exist, can you paste some code snippet to
reproduce out your problem?
====================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
david lei
8/28/2004 1:54:51 PM
Thanks Jeffrey,

I have solved the problem.
david.


[quoted text, click to view]

v-jetan NO[at]SPAM online.microsoft.com (
8/30/2004 1:32:14 AM
Hi David,

I am glad your problem is resolved. If you need further help, please feel
free to post. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
AddThis Social Bookmark Button