datagridview editonenter checkbox

M

mrstrong

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
 
M

mrstrong

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
 
M

mrstrong

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top