Bind datagridview column to list
I was able to make the DataGridView support editing of the first and second level properties. It only required two changes in the SubPropertyDescriptor.
But to get the DataGridView to bind to a second-level property in a data source, we only need to override the GetProperties method without parameter in the custom type descriptor. It seems that your problem is related to ASP. Sorry that I am not familiar with ASP. One point of detail — is there a way to associate the newly created TypeDescriptionProvider with the target class without modifying the class file?
I am attempting to use a combo box in a datagrid view to select a value for a field from another table. The table bound to the combo box is a contact table. I want to assign the contact table key value to a field in the doctor table. I want to use the contact name as the display value.
When I attempt to do this, even though I have the name set as the displaymember and the key as the valuemember, the key value is being displayed instead of the name. The correct display values are shown in the combobox when I click it, but as soon as I tab out of that field the key is displayed instead of the name. One comment, is that you mentioned that a downsize to using ICustomTypeDescriptor was that it required modification of the class.
However, your solution using TypeDescriptionProvider also requires that by way of the TypeDescriptionProvider attribute. You can apply your solution to any class, without having to apply the TypeDescriptionProvider attribute, by simply calling TypeDescriptor.
AddProvider to add the TypeDescriptionProvider for the type or an instance of it. That means you can implement the solution for any class without the need for its source.
ClassA contains an instance of ClassB. ClassA employs a description provider to expose properties of ClassB. ClassB contains an instance of ClassC. Nothing seems to work. I adaptaded your solution to a more generic one using generics. This is what I was looking for. The dotnet framework is an excellent tool, with many shining features. However, in my mind this represents a truly fundamental design flaw. The level of complexity that needs to be invoked here to accomplish this simple task is unacceptable.
How about overriding the CellFormatting event of the DataGridView and using reflection with something like the following?:. I am doing a "web" application and using listview and objectcontainerdatasource for binding. My classes are as follows. When I go to the edit mode of my listview, areacode get populated. But when I try to update, I am not getting the user entered value.
It shows the error message that duplicate TypeDescriptionProvider, Could you please pointing out how to solve this. It also supports sorting.
I hope it's useful to some of you:. GetValue x as IComparable;. GetValue y as IComparable;. AddProperties sub, pd, list ;. FYI, binding to nested public properties of basic types, i. February 1, at 5: February 6, at February 6, at 2: February 6, at 3: February 6, at 6: April 18, at May 9, at 4: May 15, at 1: May 23, at 3: June 8, at 6: July 4, at 7: July 19, at 4: September 18, at 7: December 19, at January 31, at 3: Harold Valdivia Garcia says: April 8, at 4: View April's Free Course.
I need a solution. Sign up today x. When I assign the datasource, the DataGridView adds the correct number of rows, but adds new columns for each of the fields in my class: I tried setting AutoGenerateColumns to false. That prevents the new columns from getting created, but does not help me with my binding issues.
Question has a verified solution. Sign up with Google. Sign up with LinkedIn. Sign up with Facebook. I would like to receive news, updates and offers from Experts Exchange. Tackle projects and never again get stuck behind a technical roadblock.