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.

Binding Grid ComboBox Column to CellValueType of struct?

Thread ID:

Created:

Updated:

Platform:

Replies:

12227 Mar 24,2004 06:57 AM Mar 25,2004 07:21 AM Windows Forms 6
loading
Tags: GridControl
Daws
Asked On March 24, 2004 06:57 AM

I have a collection of lookup objects that I''d like to display as a ComboBox in a grid. The ID property of these objects is itself a struct called EntityID. Here''s how the column is set up: // someLookupColumn_m this.someLookupColumn_m.HeaderText = "Some Lookup"; this.someLookupColumn_m.MappingName = "SomeLookupItemID"; this.someLookupColumn_m.StyleInfo.CellType = "ComboBox"; this.someLookupColumn_m.StyleInfo.CellValueType = typeof(MyCompany.Core.EntityManagement.EntityID); this.someLookupColumn_m.StyleInfo.DisplayMember = "EntityID"; this.someLookupColumn_m.StyleInfo.ValueMember = "EntityID"; I set the datasource of the lookup column to a collection of all the lookup items. Then I set the DataSource of the GridDataBoundGrid to the main collection. When editing, I get the following error message: "Object cannot be converted to target type." The MappingName is the same type as the ValueMember. I am seeing the expected values in the combobox, I just can''t edit the value. I think the problem might have something to do with the EntityID being a struct. The other strange thing is that the object model I am using has a Property named the same as its Type (ie. EntityID is EntityID). Any help would be greatly appreciated. Thanks, Daws

Administrator [Syncfusion]
Replied On March 24, 2004 07:59 AM

I am not sure about this, but try setting this.someLookupColumn_m.StyleInfo.ValueMember = ""; What this will do is make the grid use the actual object from the DataSource as the value which is what you indicate should be in the cell when you set CellValueType. This should make the value in the grid be the parent EntityID and not the child EntityID.EntityID. If you really do want it to be the child EntityID.EntityID, then I think you will have to do something like handle CurrentCellValidating, get the text from the current cell using grid.CurrentCell.Renderer.ControlText. Then code something that will take that text and retrieve the EntityID.EntityID that you want associated with the text. Once you have the proper EntityID, then you would call renderer.SetControlValue to make the combobox have your EntityID object as its value instead of whatever text the user typed in. I did not try this so I am not sure if CurrentCellValiding is the right place or not, or what other problems you might run into as you code this.

Daws
Replied On March 25, 2004 05:41 AM

Hi Clay, Thanks for looking at this. I''ve tried your suggestion, but as I expected, it doesn''t work. I get the same type conversion Exception. I probably wasn''t clear on my model. Here are my classes (Type ClassName): BindingEntityList MainCollection (implements IBindingList) Entity MainRowItem EntityID MainRowItem.SomeLookupItemID EntityList LookupCollection (implements IList) Entity SomeLookup EntityID SomeLookup.EntityID My grid''s DataSource = MainCollection My combobox column''s DataSource = LookupCollection My combobox column''s MappingName = SomeLookupItemID I''ve been trying a few more things, and I found one scenario that almost works. Here''s my current cell setup: this.someLookupColumn_m.HeaderText = "Quotation Method"; this.someLookupColumn_m.MappingName = "QuotationMethodID"; this.someLookupColumn_m.StyleInfo.CellType = "ComboBox"; this.someLookupColumn_m.StyleInfo.CellValueType = typeof(MyCompany.Business.Lookup.SomeLookup); this.someLookupColumn_m.StyleInfo.DisplayMember = "ShortName"; this.someLookupColumn_m.StyleInfo.ValueMember = "EntityID"; The result is that my initial value in this combobox cell in the first row of the grid shows the correct display value. The remaining rows show the type (ie. "MyCompany.Business.Lookup.SomeLookup"). The other strange things is that the values in the combobox, when it is expanded, are just a list of types (ie. "MyCompany.Business.Lookup.SomeLookup"). If I select one of the items, it does contain the right data and set the correct value for the mapped property name. I just need to get it showing the proper information. Any assistance would be greatly appreciated. Thanks, Daws

Daws
Replied On March 25, 2004 05:52 AM

I was trying make everything general, but I missed a couple lines... These two lines: >this.someLookupColumn_m.HeaderText = "Quotation Method"; >this.someLookupColumn_m.MappingName = "QuotationMethodID"; Should be: >this.someLookupColumn_m.HeaderText = "Some Lookup"; >this.someLookupColumn_m.MappingName = "SomeLookupItemID"; Regards, Daws

Administrator [Syncfusion]
Replied On March 25, 2004 06:11 AM

I do not understand these two lines: this.someLookupColumn_m.StyleInfo.CellValueType = typeof(MyCompany.Business.Lookup.SomeLookup); this.someLookupColumn_m.StyleInfo.ValueMember = "EntityID"; The CellValueType should be the type of the object in the grid column. The second line says that the property named "EntityID" is to be used to provide the object for the grid cell when you use the dropdown. Is the property named "EntityID" of type MyCompany.Business.Lookup.SomeLookup?

Daws
Replied On March 25, 2004 07:11 AM

Thanks, that was it. I changed this back to the proper type and it worked. I''m not sure how this was any different than the original way I had it set up. But it is working now, so I am happy. Thanks, Daws

Daws
Replied On March 25, 2004 07:21 AM

Okay, I found the real source of my original problem. I had only implemented IList on my Lookup collection. Once I implemented IBindingList it began to work properly as a datasource for the ComboBox column. That, in combination with Clay''s correction, fixed the issue. Regards, Daws

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.

;