dvcolgan dvcolgan - 5 months ago 36
Vb.net Question

Datagridview cell turns black when accessing EditedFormattedValue?

I have a winforms application that uses a datagridview. When I access the EditedFormattedValue of a cell while it is in edit mode, sometimes, but not always, the whole cell turns black. Is this a feature of the datagridview, perhaps some sort of validation feature I need to turn off?

I have found a couple of other mentions of this problem while googling. None of the threads seem to know what the answer is either:

Here not calling Application.DoEvents solved the problem, but I am not calling DoEvents.

http://www.tek-tips.com/viewthread.cfm?qid=1277303&page=1

http://social.msdn.microsoft.com/Forums/en/winformsdatacontrols/thread/d9bf784d-617d-4a35-8125-fe8f67987fa2

Here no one knew why it was happening, but responders suggest setting the background color to white. That seems like a hack, and I'd like to know why this is happening. Also, changing the background color doesn't remove the black background for me.

Answer

Well, though I haven't been able to figure out why this is happening with the dataGridView1.CurrentCell.EditedFormattedValue, I found that using the dataGridView1.EditingControl.Text value gets the same value and doesn't mess with the cell formatting. So, I guess that solves my problem.

Comments