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

GridView and Enum

5 Answers 314 Views
GridView
This is a migrated thread and some comments may be shown as answers.
BEFA
Top achievements
Rank 1
BEFA asked on 03 May 2010, 02:47 PM
Hi

I've one question about the radGridView:

I want to bind a list of object (where I have an Enum property called Status) to my radGridView.

the problem is when I try to update a row I have an exception when I update the property Status, and I have the same problem when I try to set the related filter.

One solution was to create a custom Column and a Custom filter and then my grid work fine, and then I have to define the binding by myself.

My question is : when I set the grid DataSource by code and without define the mapping (cells definitions) It is possible to use automatically this custom column (and filter) when the column source is an Enum?

Then, if I have to class (ClassA, ClassB) with an Enum Property and if I try to set the Grid DataSource with a List of ClassA or ClassB, my grid detect my Enum property and  use the custom column.


Thanks for your response



5 Answers, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 06 May 2010, 09:55 AM
Hi BEFA,

Currently, this functionality is not supported in the RadGridView control. For your scenario you must make a custom column, map the Status property to the FieldName and use custom filtering. Another approach is to use unbound column and cell formatting to manually manipulate the logic for getting/setting cell values and displayed information.

For future editions of this control we plan to extend the functionality of filter row to support Enum types. Currently you can use only custom filtering in this case.

All the best,

Julian Benkov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Martin
Top achievements
Rank 1
answered on 04 Apr 2011, 12:59 PM
When will this functionality be available please ? I have Q1 2011 and it's not there yet !
0
Svett
Telerik team
answered on 07 Apr 2011, 08:59 AM
Hi Martin,

This functionality is available out of the box in the latest version of RadGridView (Q1 2011). I have enclosed a sample project that demonstrates the enum type support.

Greetings,
Svett
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Martin
Top achievements
Rank 1
answered on 07 Apr 2011, 09:12 AM
Svett, thanks for taking the time to provide the sample.

I loaded it into VS2010 and ran it. When I enable filtering on the grid and select a value from the DropDownList I receive the same error that I originally reported, "Input string was not in a correct format.".

The stacktrace follows below but from this I conclude that the binding of Enums to the Grid seems fine but the Filtering on enum values does not work in Q1 2011.

   at Telerik.WinControls.UI.RadDataConverter.ThrowFormatException(Exception ex, String message)
   at Telerik.WinControls.UI.RadDataConverter.ThrowFormatException(Exception ex)
   at Telerik.WinControls.UI.RadDataConverter.Format(Object value, Type targetType, Boolean coerceNullValue, IDataConversionInfoProvider converstionInfoProvider)
   at Telerik.WinControls.UI.GridDataCellElement.ApplyFormatString(Object value)
   at Telerik.WinControls.UI.GridCellElement.SetContentCore(Object value)
   at Telerik.WinControls.UI.GridFilterCellElement.SetContent()
   at Telerik.WinControls.UI.GridDataCellElement.set_Value(Object value)
   at Telerik.WinControls.UI.GridFilterCellElement.set_Value(Object value)
   at Telerik.WinControls.UI.GridFilterCellElement.Editor_ValueChanged(Object sender, EventArgs e)
   at Telerik.WinControls.UI.BaseInputEditor.OnValueChanged()
   at Telerik.WinControls.UI.BaseGridEditor.OnValueChanged()
   at Telerik.WinControls.UI.RadDropDownListEditor.DropDownListElement_SelectedIndexChanged(Object sender, PositionChangedEventArgs e)
   at Telerik.WinControls.UI.RadDropDownListElement.OnSelectedIndexChanged(Object sender, PositionChangedEventArgs e)
   at Telerik.WinControls.UI.RadDropDownListElement.NotifyOwner(PopupEditorNotificationData notificationData)
   at Telerik.WinControls.UI.PopupEditorElement.listElement_SelectedIndexChanged(Object sender, PositionChangedEventArgs e)
   at Telerik.WinControls.UI.RadListElement.OnSelectedIndexChanged(Int32 newIndex)
   at Telerik.WinControls.UI.RadListElement.HandleSelectOne(Int32 newIndex)
   at Telerik.WinControls.UI.RadListElement.ProcessSelection(Int32 newIndex, Boolean onMouseDrag, InputType inputType)
   at Telerik.WinControls.UI.RadListElement.HandleMouse(Object sender, RoutedEventArgs args)
   at Telerik.WinControls.UI.RadListElement.OnBubbleEvent(RadElement sender, RoutedEventArgs args)
   at Telerik.WinControls.RadElement.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)
   at Telerik.WinControls.RadItem.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)
   at Telerik.WinControls.RadElement.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)
   at Telerik.WinControls.RadElement.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)
   at Telerik.WinControls.RadItem.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)
   at Telerik.WinControls.RadElement.RaiseRoutedEvent(RadElement sender, RoutedEventArgs args)
   at Telerik.WinControls.RadElement.DoMouseUp(MouseEventArgs e)
   at Telerik.WinControls.ComponentInputBehavior.OnMouseUp(MouseEventArgs e)
   at Telerik.WinControls.RadControl.OnMouseUp(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at Telerik.WinControls.RadControl.WndProc(Message& m)
   at Telerik.WinControls.UI.RadPopupControlBase.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at RadGridViewEnum.Program.Main() in C:\Temp\RadGridViewEnum\RadGridViewEnum\Program.cs:line 18
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
0
Svett
Telerik team
answered on 12 Apr 2011, 04:14 PM
Hello Martin,

This is a known issue in Q1 2011. I am glad to inform you that it will be addressed for the upcoming service pack, which will be released in the middle of April. In the meantime, you can use the following work around:
 

public class MyGridFilterCellElement : GridFilterCellElement
    {
        public MyGridFilterCellElement(GridViewDataColumn col, GridRowElement row)
            : base(col, row)
        {
 
        }
 
        protected override Type ThemeEffectiveType
        {
            get
            {
                return typeof(GridFilterCellElement);
            }
        }
 
        protected override string ApplyFormatString(object value)
        {
            if (value == null || value is string)
            {
                return Convert.ToString(value);
            }
 
            return base.ApplyFormatString(value);
        }
    }

You should replace the default GridFitlerCellElement in the CreateCell event:

private void radGridView1_CreateCell(object sender, Telerik.WinControls.UI.GridViewCreateCellEventArgs e)
{
    if (e.CellType == typeof(GridFilterCellElement))
    {
        e.CellType = typeof(MyGridFilterCellElement);
    }
}

Best wishes,
Svett
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
BEFA
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Martin
Top achievements
Rank 1
Svett
Telerik team
Share this question
or