We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Strange Behavior in custom GridComboBoxCellRenderer

Hi,

we have investigated a strange behavior in the GGC. Attached is a simple example which helps to explain the issue (it is just a fast dirty hack).

So our GGC is bound to a business object which implements IBindingList. Furthermore we have implemented a custom cell renderer to handle our custom objects. We use the OnValidate method of the derived GridComboBoxCellRenderer. Now when you start the attached example, directly click in the append new line row, enter "5" (as numeric value) and press return. So as I understand the binding mechanism, the binding list adds a new object to its internal list implementation when you enter the value "5". Now when you press return the OnValidate method is called. So in this method we use the ControlValue or the CurrentStyle.CellValue to use the type definition for validation. The problem is, that both - the ControlValue and the CurrentStyle.CellValue contain a null reference. So how can I get the value. I know the ControlText property contains the string, but I need to get the underlyling object. The CurrentStyle.CellValueType contains the type information, but the CellValue itself is a null reference.

It would be nice if you could help us.

Cheers,
Jack

OnValidateInCustomRenderer.zip

3 Replies

AD Administrator Syncfusion Team May 11, 2007 05:09 PM UTC

One way around this problem is to cache the object in an renderer.OnInitialize override, and then use this cached object in OnValidate. OnInitialize is called when your renderer is initially activated for editing.

private MyObject currentObject = null;
protected override void OnInitialize(int rowIndex, int colIndex)
{
base.OnInitialize(rowIndex, colIndex);
currentObject = this.CurrentStyle.CellValue as MyObject;
}

protected override bool OnValidate()
{
return currentObject.Validate(TextBox.Text);
}


JA Jack May 11, 2007 06:02 PM UTC

Hi Clay,

thanks for your suggestion, but the CurrentStyle.CellValue is a null reference too in the "append new line" row even for the OnInitialize method. When you start the attached example, click in the new line row cell of the column (this must be the first click) enter a numeric value and press return. Then the CellValue is a null reference in the OnInitialize method.

Cheers,
Jack


AD Administrator Syncfusion Team May 12, 2007 12:54 AM UTC

Here is your sample back. I added some code to your derived BindingList class to override EndNew and AddNewCore. In the AddNewCore, the AddingNew event was raised. The Renderer was modified to listen to the AddingNew event so it could get a reference to the new MyRow object, and from that new object, the renderer could set the CellValue for the new object. The EndNew override was added to make sure the new object got added to the list.

The custom cell renderer has no knowledge of your custom object unless you add code that allows it to access the custom information. Letting the renderer listen to AddingNew gives it access to the new object which it can then work with to place in the style.CellValue.


ForumSample.zip

Loader.
Live Chat Icon For mobile
Up arrow icon