This is a migrated thread and some comments may be shown as answers.

Values and Customer Editors

2 Answers 80 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Hannes
Top achievements
Rank 1
Hannes asked on 01 Mar 2011, 02:48 PM
I have created a custom editor for GridView (based on BaseGridEditor).

The nature of my editor is that the "Value" you select in the editor is actually two values (integers), there is also a text description I would like to be displayed in the grid when the cell is not edited.

I tried to make the editor expose an object of a class encapsulating my two values and the text description with the Value property. (The class had a ToString implementation that returned the text description).
I also tried to bind the grid to something like
Grid.DataSource = from s in whateversource select new {irrelevantfield = "whatever", complexfield = new ComplexClass { v1=o.v1, v2=o.v2, description=o.Description}};

However, the grid doesn't seem to want to remember my ComplexClass value, it seems it just runs ToString on what it gets from the editors Value property, because when I edit the cell again it sets the editors Value property to a string.


Can you recommend a way to
1. handle the selected "value" and text representation separately.
2. handle selected "values" that are complex, that is they are multiple values.

Thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 01 Mar 2011, 03:08 PM
Hello Hannes,

Just use a custom cell, and you will be able to define the behavior of the cell as well as the behavior of the editor.
Or you can just override the ToString() of that ComplexClass to return description.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
Hannes
Top achievements
Rank 1
answered on 01 Mar 2011, 04:59 PM

Yes, subclassing GridViewDataColumn and overriding

GetDefaultEditorType() and DataType did the trick.

Thanks
Tags
GridView
Asked by
Hannes
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Hannes
Top achievements
Rank 1
Share this question
or