I have been working with the MaskedTextBoxCell provided by the SDK and needed to display the mask result in view mode when I found this issue.

In order to get the value to be masked during display mode I had to override the Paint method of the MaskedTextBoxCell class as follows. I have trimmed out all of my code creating a MaskedTextBoxProvider to simplify the example.

Code Snippet

protected override void Paint(

System.Drawing.Graphics graphics,

System.Drawing.Rectangle clipBounds,

System.Drawing.Rectangle cellBounds,

int rowIndex,

DataGridViewElementStates cellState,

object value,

object formattedValue,

string errorText,

DataGridViewCellStyle cellStyle,

DataGridViewAdvancedBorderStyle advancedBorderStyle,

DataGridViewPaintParts paintParts)

{

Console.WriteLine(

"Row '{0}'DataBoundItem '{1}'",

rowIndex,

this.OwningRow.DataBoundItem);

Console.WriteLine(

"Row '{0}'Other DataBoundItem '{1}'",

rowIndex,

DataGridView.Rows[rowIndex].DataBoundItem);

// My Code removed...

// Create a mask provider to formatvalue for display

base.Paint(

graphics,

clipBounds,

cellBounds,

rowIndex,

cellState,

value,

formattedValue,

errorText,

cellStyle,

advancedBorderStyle,

paintParts);

}

The result of the following code when bound to a list containing more then one item would be:

Row '0'DataBoundItem 'MyNamespace.MyObject'

Row '0' Other DataBoundItem 'MyNamespace.MyObject'

Row '1' DataBoundItem ' '

Row '1' Other DataBoundItem 'MyNamespace.MyObject'

As you can see something is happening to the Owning Row of the second record. Does this have to do with the current sections or should I not rely on the Owning Row?

Thanks in advance