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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with checkboxes in DataGridView

Status
Not open for further replies.

mjjks

Programmer
Jun 22, 2005
138
US

Hi. I need some advice as I got stuck a little.

So, I have a windows form with a DataGridView that gets populated with table data for Add/Edit/Delete operations.
Data generally is entered through another interface and checkboxes data on database side(SQL2K) are defined as bit (NOT NULL) type.

Problem is this: when I try to create new record and tab through cells, when I move to another row, it complains that checkbox column cannot be NULL.
I expect checkboxes to have value of 0 or false, if I don't check them.

If I toggle it ON using spacebar, no error is generated but record is not saved when I close and reopen form.

Only time it works if I check checkboxes with a mouse.
I tried to set checkbox values to false on CellEnter event, if if it's null or false. This doesn't give me an error, but doesn't save record either.

The way cell gets update is this: on CellEndEdit event I call UpateData() function with sqlAdpData.Update(datData);

Any ideas how to make it working? If you need additional info, please let me know.
Thanks much.




 
I am not too familiar with the functions you mention, but wouldn't you want to use something like Insert(datData) for a new record? Update should be used to change an existing record.

Then again, I do most of my db access through queries or stored procedures because I like the extra control they give me. So that as well may be an option for you.

Hope this helps,

Alex

Ignorance of certain subjects is a great part of wisdom
 

Thanks for the opinion Alex.

Yes, for most applications I use stored procedures or command object. For this project however, user has requirements to pick a table name from drop-down and have all table's columns loaded.

So, I don't really know table structure, and it might change as columns get added or removed. Tables are mostly lookup tables.

DataGridView has Allow Add/Edit/Delete options and all operations supposed to be handled by grid itself through attached data Source.

So, datData is grid's source and it has new row. And then you update SqlAdapter. UpdateData() function is created by me, it's not build in and has this entry:

private void UpdateData()
{
try
{
sqlAdpData.Update(datData);

}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top