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.

Issue with binding inherited objects into grid

Thread ID:

Created:

Updated:

Platform:

Replies:

12608 Apr 5,2004 02:17 AM Apr 5,2004 03:14 PM Windows Forms 2
loading
Tags: GridControl
Damien Sawyer
Asked On April 5, 2004 02:17 AM

Hi, My issue is a little confusing, but I''ll try my best to explain it. I have two classes, clsItem and clsTotalItem. The later inherits the former. Basically, clsTotalItem overrides a number of the properties of it''s base class, providing totals information for a collection of clsItem classes. I am adding instances of these object to an arraylist and then binding that arraylist to the grid control. The idea being that total''s rows appear in the grid below items. Sorting is done via a customised comparer attached to the arraylist. The grid has nothing to do with it. This all works fine - half of the time. If the arraylist is sorted so that one of the clsItem objects is ''first'', then the grid populates fine. The clsTotalItem objects drop into place nicely. However, if the grid is sorted so that the first item is a clsTotalItem object, then the grid falls over with a message along the lines of ''object not of expected type'' (something like that, I''m writing this from home and don''t have the problem in front of me). I''m ''guessing'' that internally the grid is looking at the type of object in the first row of the data source and storing it somewhere. I assume that it is then casting the other rows into that type. This makes sense that it works fine if the first object was a clsItem... as clsTotalItem can be cast into clsItem fine. However, it makes sense that it will not work the other way because clsItem cannot be cast into clsTotalItem. Any suggestions how to work around this? I guess that I need a way to force the grid to always assume that the class is clsItem, regardless of what the first row is. If any of this is unclear, please ask for clarification. Thanks in advance, I look forward to hearing from you. Damien

Administrator [Syncfusion]
Replied On April 5, 2004 04:25 AM

One way to handle this is to have your arraylist be strongly typed by implementing ITypedList. There are some snippets in http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=9194. There is a sample project in this thread. http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=11215

Damien Sawyer
Replied On April 5, 2004 03:14 PM

Thanks Clay, That''s done it!! :-)

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.

;