Say I have a set of Business Objects that look like this:
public class MasterObject
{
public string Description {get; set;}
private Settings _setting = new Settings();public Settings MasterSettings {get { return _setting; }}
private List<DetailObject> _details = new List<DetailObject>();
public List<DetailObject> Details
get { return _details; }}
}
public class DetailObject
public string Description { get; set; }
public Option1 Option { get; set; }
pubilc Option2 Option {get; set; }}
public class Settings
public string Setting1 {get; set;}
public string Setting2 {get; set; }
public string Setting3 {get; set; }
public class Option
public long id {get; set;}
public string Description {get; set;}}
I want to bind to a list of Masterobjects, and I have these constraints:1) Display and edit the MasterObject.Description.2) Display and edit the MasterObject.MasterSetting property a) Editing is performed by selecting a MasterSetting from a list. b) The display text of the MasterSetting is determined by arbitrary means (i.e., ToString() will be an insufficient means to discover the display text.3) Display and edit the list of DetailObjects that are contained by the MasterObject.4) Display and edit the 2 Options on the DetailObjects using a list. a) like the MasterSetting, the display text is determined by arbitrary means; the ToString() function will be insufficient for discovering the display text. My understanding of the UltraGrid is that I'll need two bands to get started--one each for the Master and Detail objects.My first problem is that the cells containing the complex object properties show the class name (I need to set the display text to one of the properties, but which property is determined at runtime).My second problem is that I don't see how to specify the list editing control, or the list of Settings and Options classes that the lists should pull from.
I have been unable to find a sample that is on point. All of the binding-to-business-objects samples I have seen so far rely on "flat" business objects.Where do I go from here?ThanksChris McKenzie
Assuming that the DataSource notifies the grid of the newly-added row, then yes, I think using BeforeRowInsert will work. If it does not send notificaitons, then you may have to call grid.Rows.Refresh to get it to recognize the new row. And you will probably want to find the new row in the grid and set it as the ActiveRow manually.
Thanks for you reply.Your suggestion of using the BindingList in place of the List<> assumes that I have the ability to change the datatype of the list property. Let's say I don't have that freedom. I'm assuming that the difficulties is that the control doesn't now how to a) create my custom object and b) add it to the collection property of the parent object.
I can understand the first issue, but if the control raises some event that allows me to construct the object, then adding it to the underlying IList <> interface shouldn't be that hard. Even if it is that hard, it seems like the control should provide an event interface for me to add it to the underlying datasource.
So, can I do something like handle the BeforeRowInsert event, create the object, add it to the underlying list, and expect the ultragrid to continue processing?
Hi Chris,
If you intend for these objects to be used for binding, I recommend using BindingList<> instead of List<>. The BindingList is more robust and allows for easier binding.
Anyway, let's say you create a BindingList<MasterObject> and use this as the DataSource of the grid. At the root level, your grid will create columns on this band for all of the public properties of the MasterObjects, so that would be Description, MasterSettings, and Details. The Description field is a string, so this is no problem and the user can edit the Description in the grid. The MasterSettings property returns an object, so all the grid can do in this case is display the ToString of the object. It cannot know how to create new instances of this object or all the user to edit it.
Now... it sounds like what you want to do is not allow the user to create new MasterSettings or edit the properties of the MasterSettings, but rather present the user with a list of possible MasterSettings from a list. This is very easy to accomplish using a ValueList. There are two approaches you can take:
1) Create a ValueList in code and populate it manually with the list of Settings objects you want. The way this would work is that the ValueListItems.Add method takes two params: DisplayText and DataValue. The DisplayText in this case would be whatever you want the display text to be and the DataValue in this case would be a Settings. The user could then select an item from the list and the grid will dispay the DisplayText of the item while storing the Settings in the grid cell.
2) The alternative is to use the UltraDropDown control as your ValueList. This would be you would need to create another List or BindingList that contains the display text you want for each Settings and then the Settings itself in each row.
crmckenzie said:My first problem is that the cells containing the complex object properties show the class name (I need to set the display text to one of the properties, but which property is determined at runtime).
I'm working on this too. We should wait for the "official answer". But...I'm guessing the answer is a data filter (the IEditorDataFilter interface). I just implemented one and it lets me display what I want in the cell and convert the text (entered by the user) to an object.
I've been reading this: http://help.infragistics.com/Help/NetAdvantage/NET/2008.1/CLR2.0/html/WinGrid_Data_Filtering_and_Translation.html