By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,757 Members | 1,186 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,757 IT Pros & Developers. It's quick & easy.

datagridview checkbox

P: n/a
Gday,

I have a datagridview that I am creating the columns programatically
which all seems to work fine. I have a couple of dropdown boxes, so I
have set the editMode= EditOnEnter.

Now my checkboxes dont seem to work, and the datagridview throws a
dataerror when I try to leave the cell after trying to check/uncheck
the checkbox?!

Anyone know why this might be happening?

Thanks,

Peter

Sep 7 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Sep 7, 12:22 pm, mrstrong <p.str...@gmail.comwrote:
Gday,

I have a datagridview that I am creating the columns programatically
which all seems to work fine. I have a couple of dropdown boxes, so I
have set the editMode= EditOnEnter.

Now my checkboxes dont seem to work, and the datagridview throws a
dataerror when I try to leave the cell after trying to check/uncheck
the checkbox?!
Ok - on further investigation - it seems to be that when the
datagridview has EditMode=EditOnEnter, and when I go to add a new row
by clicking on one of the checkboxes, for some reason it is setting
the 'EditedFormattedValue' of the checkbox that I clicked on for the
new row to be the first value of the comboxbox that is the first
column in the datagridview. This is what's causing the dataerrors -
the checkbox's 'EditedFormattedValue' is getting set to a string
value, where it can only take a boolean.

Try setting up a datagridview with a combobox as the first column, and
a checkbox as the second column, and see if you get the same thing
when you go to add a new row by clicking on the checkbox.

Thanks,

Peter

Sep 12 '07 #2

P: n/a
On Sep 12, 12:17 pm, mrstrong <p.str...@gmail.comwrote:
On Sep 7, 12:22 pm, mrstrong <p.str...@gmail.comwrote:
Gday,
I have a datagridview that I am creating the columns programatically
which all seems to work fine. I have a couple of dropdown boxes, so I
have set the editMode= EditOnEnter.
Now my checkboxes dont seem to work, and the datagridview throws a
dataerror when I try to leave the cell after trying to check/uncheck
the checkbox?!

Ok - on further investigation - it seems to be that when the
datagridview has EditMode=EditOnEnter, and when I go to add a new row
by clicking on one of the checkboxes, for some reason it is setting
the 'EditedFormattedValue' of the checkbox that I clicked on for the
new row to be the first value of the comboxbox that is the first
column in the datagridview. This is what's causing the dataerrors -
the checkbox's 'EditedFormattedValue' is getting set to a string
value, where it can only take a boolean.

Try setting up a datagridview with a combobox as the first column, and
a checkbox as the second column, and see if you get the same thing
when you go to add a new row by clicking on the checkbox.
Hmmm...I actually tried a blank project, added a
datagridview with two columns - one a combo box and the other a
checkbox and it worked perfectly...

I have a method attached to the datagridview for
defaultValuesNeeded, so mabye this was actually causing something
screwy to happen
here...

I have resolved to use the cellenter method of the
datagridview and call 'SendKeys.Send("{F4}");' if the cell is a combo
and this gives the desired action that the combo will dropdown when it
is first clicked (this is with editmode set back to its default value
of 'EditOnKeystrokeOrF2'). The checkboxes now behave as expected.

I originally had issues with sendkeys, as if you clicked on a
dropdown in to add a new row, and held down the mouse it would keep on
adding new rows. So I added this code in the cellenter method which
seemed to stop this
happening:

dgv.AllowUserToAddRows = false;
dgv.AllowUserToAddRows = true;

More than one way to skin a cat...

When I get time I'll go back and try to see if the defaultValuesNeeded
method might be causing any issues (currently the datatable it is
bound to has some required fields).

Thanks for your assistance.

Regards,

Peter

Sep 24 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.