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

Binding Grid ComboBox Column to CellValueType of struct?

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

6 Replies

AD Administrator Syncfusion Team March 24, 2004 12:59 PM UTC

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.

DA Daws March 25, 2004 10:41 AM UTC

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

DA Daws March 25, 2004 10:52 AM UTC

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

AD Administrator Syncfusion Team March 25, 2004 11:11 AM UTC

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?

DA Daws March 25, 2004 12:11 PM UTC

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

DA Daws March 25, 2004 12:21 PM UTC

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

Live Chat Icon For mobile
Up arrow icon