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

TypeConverter Support

7 Answers 248 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Evan
Top achievements
Rank 1
Evan asked on 27 Jul 2011, 09:49 PM
I am testing the demo version of the GridView control (Q2 2011 version) and by integrating it into my current project. I am running into an issue though, because my current implementation makes heavy use of TypeConverters to display data in WPF controls. To help explain my question, lets assume a couple of things:

First, we have a generic superclass called Super, which has a property that is an ObservableCollection<Super> which is called Stuff. 

In another assembly, we have some generated code that defines subclasses of Super, each with their own set of properties. Some of the properties of this subclass have custom type converters also defined in the same file (these type converters are automatically generated). For example:
public class Person : Thing
{
  [Browsable(true)]
  [TypeConverterAttribute(typeof(JobIDTypeConverter))
  public Int64 JobID
  {
    get; set;
  }
  private class JobIDTypeConverter : TypeConverter
  {
    public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
    {
      return true;
    }
    public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
    {
      //jobIDDisplayNames is an array of strings
      return new StandardValesCollection(jobIDDisplayNames);
    }
    public override CanConvertFrom(...) { ... }
    public override ConvertTo(...) { ... }
    public override ConvertFrom(...) { ... }
  }
}

I abbreviated some of the methods but assume that they convert Int64s to Strings and vice-versa.

In addition, these subclasses fill the Stuff collection with some elements. Now, in my application we only refer to these subclasses by loading the assembly programmatically and using reflection.

When we pop up a GridView and bind it to the Stuff collection like so: 
RadGridView grid = new RadGridView();
grid.ItemsSource = mySuper.Stuff;
We get what we wanted to see, all the properties of the subclass are reflected on and columns are automatically generated for them. We can edit them and ones that were not Browsable don't show up, ones that are ReadOnly can't be edited, etc. The only downside is that our custom type converters do not appear to work, and in fact it seems that they are never called by the GridView. We know that the TypeConverter code does work, as we have used them with other WPF controls for quite some time now without issue.

We are willing to change the way we define our TypeConverters if necessary (given that the WPF PropertyGrid that you provide would also support the TypeConverters given the same change), but we can not feasibly change to using IValueConverters, as that only provides us with ConvertTo and ConvertFrom methods, and what we really want is to be able to use the StandardValuesCollection (or something similar) that TypeConverter provides us, to avoid writing a lot of extra code in order to handle this conversion ourselves.

I saw a thread that somewhat pertained to this issue here, which claimed that TypeConverter support was added in the latest release but the author never wrote back to confirm if the changes worked for him or not. Please let me know what steps we should take to solve this issue. We are very interested in purchasing your product because everything else about the GridView seems to work perfectly for us, but this is a problem which must be solved. Thanks in advance.

7 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 03 Aug 2011, 10:25 AM
Hi Evan,

Sorry for the late reply.

It seems that you've hit a bug in our control (indeed TypeConverter is not called on edit).
We are doing our best to resolve this issue.
I'll update you via this forum thread when we have more information.
 

Regards,
Nedyalko Nikolov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Nedyalko Nikolov
Telerik team
answered on 09 Aug 2011, 07:43 AM
Hi Evan,

We believe that we've managed to fix the issue with "TypeConverter" support.
Could you please try your scenario with our latest internal build (2011.2.0808) and let me know how it goes?

Greetings,
Nedyalko Nikolov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Evan
Top achievements
Rank 1
answered on 09 Aug 2011, 03:50 PM
Thank you for the quick response. The new internal build is a step in the right direction but does not totally solve the issue I originally described. TypeConverters are now properly called when leaving a field, but there remains two problems.

First, on a property of type Int64 which has a TypeConverter that converts String to Int64, the grid's built in validation will stop you from inputting a string into that properties cell. It appears that what's happening right now is that whatever value is in the cell when you exit it is transformed into a string and thrown at the TypeConverter which isn't exactly the behavior that we are looking for. We're trying to have a human readable input such as the string "book" transform into the correct Int64 value behind the scenes. This is essentially what enums do, but we can not use them in our case because they can't be modified at runtime.

The other problem is that when a user edits a field which has a TypeConverter that supports having a collection of standard values (that is, theTypeConverter.GetStandardValuesSupported(...) returns true), a dropdown combobox should be provided to the user. Obviously this is there to help them in the case that they don't know what the magic string should be that will allow them to set that value the way they need it. Again, this is similar to enums but as mentioned enums are not usable in our case.

Thank you again for the response. I am very impressed that in less than a week you were able to put out an internal build that was very close to what I needed.
0
Nedyalko Nikolov
Telerik team
answered on 15 Aug 2011, 01:24 PM
Hi Evan,

Sorry for the late reply.

Later today we will be able to download our latest internal build, which will fix your first issue.
About the second suggestion - for the time being we don't have plans to support TypeConverter.GetStandardValuesSupported() out of the box. However you could use our dedicated GridViewComboBoxColumn.
Let me know how your scenario works with today's internal build.

Kind regards,
Nedyalko Nikolov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Evan
Top achievements
Rank 1
answered on 15 Aug 2011, 08:13 PM
I just plugged in the new internal build and I am sad to say that this one does not solve my problem either. Upon displaying the grid or attempting to edit a property that has a TypeConverter I get an ArgumentNullException. The message is "Argument can not be null. Parameter name: type" and the top of the stacktrace is:
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at Telerik.Windows.Controls.GridViewBoundColumnBase.GetPropertyDescriptorConverter()
at Telerik.Windows.Controls.GridViewDataColumn.CreateTextBoxEditor(Binding valueBinding)
at Telerik.Windows.Controls.GridViewDataColumn.CreateEditor()
at Telerik.Windows.Controls.GridViewDataColumn.CreateCellEditElement(GridViewCell cell, Object dataItem)
at Telerik.Windows.Controls.GridView.GridViewCell.SetEditorContent()
at Telerik.Windows.Controls.GridView.GridViewCell.ShowEditor()
at Telerik.Windows.Controls.GridView.GridViewCell.ToggleEditor()
at Telerik.Windows.Controls.GridView.GridViewDataControl.OnCellEditModeChanged(GridViewCell cell, Boolean newIsInEditMode)
at Telerik.Windows.Controls.GridView.GridViewCell.IsInEditModeChanged(DependencyObject target, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
at Telerik.Windows.Controls.GridView.GridViewCell.set_IsInEditMode(Boolean value)
at Telerik.Windows.Controls.GridView.GridViewDataControl.SwitchCellToEditMode(GridViewCell cell)
at Telerik.Windows.Controls.GridView.GridViewDataControl.BeginEdit(GridViewCell gridViewCell, RoutedEventArgs editingEventArgs)
at Telerik.Windows.Controls.GridView.GridViewDataControl.OnCellMouseDown(GridViewCell cell, MouseButtonEventArgs args)
at Telerik.Windows.Controls.GridView.GridViewCell.OnMouseLeftButtonDown(MouseButtonEventArgs e)

The full stacktrace is massive, but the above is where any references to Telerik dlls appear to be. I can provide more of the stacktrace upon request if it is necessary. I did not see any other hints in the Exception object that would give further information about this exception.

Thank you again for your continued support as we work through this issue. I look forward to seeing it resolved.
0
Nedyalko Nikolov
Telerik team
answered on 16 Aug 2011, 07:06 AM
Hi Evan,

Could you please send me a sample application that I can debug on my side or at least a snippet from your xaml, BO and TypeConverter declarations?
Thank you in advance.

Greetings,
Nedyalko Nikolov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Evan
Top achievements
Rank 1
answered on 16 Aug 2011, 07:31 PM
Hi Nedyalko,
I have added a post to the support ticket I raised for this issue because forum posts do not allow attachments.

Thanks,
Evan
Tags
GridView
Asked by
Evan
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Evan
Top achievements
Rank 1
Share this question
or