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
close icon

IBindingLIst DataSource problem, plese help me

Hello, I have a problem with GridDataBoundGrid: I''m using a custom DataSource of a collection that implements IBindingList. The collection contains Class Person''s objects, this following is class Person: public enum EGender { Man = 1, Woman } public class Person { private string name; private EGender gender; public string Name { get { return this.name; } set { this.name = value; } } public EGender Gender { get { return this.gender; } set { this.gender = value; } } } I construct a DataSource for the "Gender" Column . DataTable table = new DataTable(); table.Columns.Add("Value", typeof(EGender)); table.Columns.Add("Description", typeof(string)); DataRow row = table.NewRow(); row["Value"] = EGender.Man; row["Description"] = "I''m a man"; table.Rows.Add(row); row = table.NewRow(); row["Value"] = EGender.Woman; row["Description"] = "I''m a woman"; table.Rows.Add(row); gridDataBoundGrid1.Binder.InternalColumns["Gender"].StyleInfo.DataSource = table; gridDataBoundGrid1.Binder.InternalColumns["Gender"].StyleInfo.ValueMember = "Value"; gridDataBoundGrid1.Binder.InternalColumns["Gender"].StyleInfo.ValueMember = "Description"; The problem: When I change the value of gender(for example, select "I''m a woman"), there is a exception "Object type can not be converted to target type". if my collection implements ITypedList interface, I will catch a exception "Invalid cast from ystem.Int32 to EGender" please help me, thank u very much

2 Replies

AD Administrator Syncfusion Team April 16, 2004 04:58 AM UTC

I assume the Gender column in the grid''s DataSource is also of type EGender, correct? If so, try also setting; gridDataBoundGrid1.Binder.InternalColumns["Gender"].StyleInfo.CellValueType = typeof(EGender);

AD Administrator Syncfusion Team April 18, 2004 09:53 AM UTC

thank u very much! I have already added gridDataBoundGrid1.Binder.InternalColumns["Gender"].StyleInfo.CellValueType = typeof(EGender); to my code, it does not work either, I add a Breakpoint at the PropertyDescriptor.SetValueSetValue( object component, object value ); Method the value is a Int32 type object which value is 1 or 2, is the value passed by GridDataBoundGrid?If I don''t construct a DataSource for the "Gender" Column, the value will be a EGender type and the value will be {EGender.Man} or {EGender.Woman} (PS:My program returns a custom class named MyPropertyDescriptor : PropertyDescriptor collentcion in ITypedList.GetItemProperties Method, so I can watch the value passed by Grid) please help me... thanks...

Live Chat Icon For mobile
Up arrow icon