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

datagridview editonenter checkbox

P: n/a
Gday,

Why would all my checkboxes inside a datagridview stop working (ie
checked state not updating when user clicks) when the datagridview's
editmode property is changed to "EditOnEnter"?

It seems to return an error: "Formatted Value of the cell has wrong
type".

It works fine when the datagridview's editmode property is
"EditOnKeystrokeOrF2"...

Any suggestions would be most welcome!

Thanks,

Peter

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


P: n/a
On Sep 10, 4:40 pm, mrstrong <p.str...@gmail.comwrote:
Gday,

Why would all my checkboxes inside a datagridview stop working (ie
checked state not updating when user clicks) when the datagridview's
editmode property is changed to "EditOnEnter"?

It seems to return an error: "Formatted Value of the cell has wrong
type".
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:01 pm, mrstrong <p.str...@gmail.comwrote:
On Sep 10, 4:40 pm, mrstrong <p.str...@gmail.comwrote:
Gday,
Why would all my checkboxes inside a datagridview stop working (ie
checked state not updating when user clicks) when the datagridview's
editmode property is changed to "EditOnEnter"?
It seems to return an error: "Formatted Value of the cell has wrong
type".

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.