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.
Unfortunately, activation email could not send to your email. Please try again.

Custom cell renderer and custom object

Thread ID:

Created:

Updated:

Platform:

Replies:

62228 Jun 11,2007 08:53 AM Jun 13,2007 07:57 PM Windows Forms 5
loading
Tags: GridControl
Franz Gsell
Asked On June 11, 2007 08:53 AM

Hi,

we have a GGC which is bound to a custom object via binding. This custom object (BindingList) contains several "row" objects. A row object itself contains native properties (like string, int, double ...) but also custom properties. To handle these custom properties we have implemented custom cell types. I have attached a sample to explain my problem.

When you start the sample you can see a grid with three columns (First Name, Last Name, Data Object). Where the "Data Object" column is a custom property whith a custom cell type. The grid contains one row. Now make a mouse click in the cell of the first row and last column ("Data Object" column). Now when you press the arrow down key on the keyboard the focus is in the Add-New row. A new row object is automatically created and the "Data Object" column contains the value "0". Now when you press a number key to enter a new value, nothing happens. It seems the custom cell renderer doesn't get the focus.

When you press the left arrow key and then the right arrow key, you can enter a value. But with a click on the return key, the cell value isn't saved. It's difficult to describe, but the attached sample shows the behavior.

Do you know what's the problem with the custom cell renderer here? and why is the cell value not saved?

Thanks,
Markus

Franz Gsell
Replied On June 11, 2007 08:53 AM

Sorry I forgot the attachement

CustomObjectGrid.zip

haneefm [Syncfusion]
Replied On June 11, 2007 06:31 PM

Hi Markus,

Here is a modified sample that shows you "How to bind custom celltypes in a GroupingGrid?". It also uses the renderer.OnSaveChanges() method to add a new record to grid. Please try the sample and let me know if this helps.

Sample : ModifiedCustomObjectGrid.zip

Best regards,
Haneef

Franz Gsell
Replied On June 12, 2007 02:54 AM

Hi Haneef,

thank you for your modifications. So I have seen that you have removed the OnQueryCellStyleInfo and OnTableControlCurrentCellMoved method. You are currently handling the whole stuff in the OnSaveChanges method and this works fine.

The problem is that I need the OnQueryCellStyleInfo method, because in our real world example we have different cell types for the "Data Object" column, because there are different types in that column. The different types depend on another column. With the OnQueryCellStyleInfo we can set the cell type dynamically.

So your idea with the part:

else
{
typedValue = new CustomObject();
typedValue.DoubleValue = Double.Parse(TextBox.Text);
GridTableControl tc = this.Grid as GridTableControl;
GridTableCellStyleInfo info = this.Grid.Model[RowIndex, ColIndex] as GridTableCellStyleInfo;
if (tc != null && info.TableCellIdentity.DisplayElement.Kind == Syncfusion.Grouping.DisplayElementKind.AddNewRecord)
{
tc.Table.AddNew();
}
this.Grid.Model[RowIndex, ColIndex].CellValue = typedValue;
CurrentCell.IsModified = false;
return true;
}

in the OnSaveChanges method doesn't work for us - because we don't know if we have a custom object or something else. Because the same cell type can be used for another type in the same column.

Can the problem be solved with our approach (OnQueryCellStyleInfo and OnTableControlCurrentCellMoved)?

Cheers,
Markus

Franz Gsell
Replied On June 13, 2007 01:47 PM

Hi,

I just wanna bring this thread up - any news about that issue?

Cheers
Markus

haneefm [Syncfusion]
Replied On June 13, 2007 07:57 PM

Hi Markus,

You can try these code in a OnSaveChanges method and let me know if this helps.

protected override bool OnSaveChanges()
{
GridTableControl tc = this.Grid as GridTableControl;
GridTableCellStyleInfo info = this.Grid.Model[RowIndex, ColIndex] as GridTableCellStyleInfo;
ICustomObject typedValue = this.Grid.Model[RowIndex, ColIndex].CellValue as ICustomObject;
if (typedValue != null)
{
if (tc != null && info.TableCellIdentity.DisplayElement.Kind == Syncfusion.Grouping.DisplayElementKind.AddNewRecord)
tc.Table.AddNew();

ICustomObject objBaseForClass = Activator.CreateInstance(typedValue.GetType()) as ICustomObject;
objBaseForClass.DoubleValue = Convert.ToDouble(this.ControlText);
ControlValue = typedValue;
this.Grid.Model[RowIndex, ColIndex].CellValue = objBaseForClass;
CurrentCell.IsModified = false;
return true;
}
else
return false;
}

Please refer to attached sample for implementation.
CustomObjectGrid.zip

Best regards,
Haneef

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;