Property display name

10 posts, 0 answers
  1. Andrea
    Andrea avatar
    73 posts
    Member since:
    Oct 2012

    Posted 07 Sep 2017 Link to this post

    Hello, does anyone knows a way to let the RadDataFilter to show the "DisplayName" of a property (as taken from a resource file) instead of the property name in unbound mode so that I do not have to write my own parser to convert the expression between "display" and "property" ?

    [Display(Name = "DATAARR_DisplayProp", Description="DATAARR_zz_tooltip_", ResourceType=typeof(Warehouse.Magany2.loc.PKLIST_LOCALI))]       
    public Nullable<DateTime> DATAARR      
    {  
       get;
       set;
    }
        

     

    See attached image

    Best Regards

    Andrea

  2. Dimitar
    Admin
    Dimitar avatar
    2741 posts

    Posted 08 Sep 2017 Link to this post

    Hi Andrea,

    Such attributes are not supported. However, you can manually change the text in the editor and in the node. Here is an example for this:
    //change in drop down
    private void RadDataFilter1_EditorInitialized(object sender, TreeNodeEditorInitializedEventArgs e)
    {
        var editor = e.Editor as TreeViewDropDownListEditor;
        if (editor != null)
        {
            var element = editor.EditorElement as BaseDropDownListEditorElement;
            element.ListElement.VisualItemFormatting -= ListElement_VisualItemFormatting;
            element.ListElement.VisualItemFormatting += ListElement_VisualItemFormatting;
        }
    }
     
    private void ListElement_VisualItemFormatting(object sender, VisualItemFormattingEventArgs args)
    {
        if (args.VisualItem.Text == "Name")
        {
            args.VisualItem.Text = "Custom Text";
        }
    }
    //change in text
    private void RadDataFilter1_NodeFormatting(object sender, Telerik.WinControls.UI.TreeNodeFormattingEventArgs e)
    {
        DataFilterCriteriaElement dataGroupFilterElement = e.NodeElement as DataFilterCriteriaElement;
        if (dataGroupFilterElement != null  )
        {
            if (dataGroupFilterElement.FieldElement.Text == "Name")
            {
                dataGroupFilterElement.FieldElement.Text = "Custom Text";
            }
            
        }
        
    }

    I hope this will be useful. Let me know if you have additional questions.

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. VaL
    VaL avatar
    27 posts
    Member since:
    Oct 2017

    Posted 02 May 2018 in reply to Dimitar Link to this post

    Hi Dimitar,

    I'm trying to apply the proposed solution, but I notice that the substitution is not complete.

    I click "New" > "Expression", and I see the correct "Custom Text".

    When I click on "Custom Text" to select another field, I see "Custom Text" as value proposed by the ComboBox, but the selected value becomes "Name".

    How can we avoid to show "Name" also there?

     

    Thank you!

     

  4. Dimitar
    Admin
    Dimitar avatar
    2741 posts

    Posted 02 May 2018 Link to this post

    Hi Valerio,

    It would be better to use a dictionary to store the names and then just change the data source of the editor. Here is an example for this:
    Dictionary<string, string> displayNames;
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        displayNames = new Dictionary<string, string>();
        displayNames.Add("loc", "Location");
        displayNames.Add("com", "Company");
     
        foreach (var item in radGridView1.Columns)
        {
            if (displayNames.ContainsKey(item.FieldName))
            {
                item.HeaderText = displayNames[item.FieldName];
            }
     
        }
        radDataFilter1.EditorInitialized += RadDataFilter1_EditorInitialized;
        radDataFilter1.NodeFormatting += RadDataFilter1_NodeFormatting;
     
    }
     
    private void RadDataFilter1_NodeFormatting(object sender, TreeNodeFormattingEventArgs e)
    {
        DataFilterCriteriaElement dataExpressionFilterElement = e.NodeElement as DataFilterCriteriaElement;
        if (dataExpressionFilterElement != null)
        {
            var node = dataExpressionFilterElement.Data as DataFilterCriteriaNode;
            if (displayNames.ContainsKey(node.PropertyName))
            {
                dataExpressionFilterElement.FieldElement.Text = displayNames[node.PropertyName];
            }
        }
    }
     
    private void RadDataFilter1_EditorInitialized(object sender, Telerik.WinControls.UI.TreeNodeEditorInitializedEventArgs e)
    {
        var editor = e.Editor as TreeViewDropDownListEditor;
        DataFilterCriteriaElement criteriaElement = e.NodeElement as DataFilterCriteriaElement;
     
        if (editor != null && criteriaElement != null )
        {
            if (criteriaElement.EditingElement is DataFilterFieldEditorElement)
            {
                var element = editor.EditorElement as BaseDropDownListEditorElement;
                element.DataSource = displayNames;
                element.ValueMember = "Key";
                element.DisplayMember = "Value";
            }  
        }
    }

    Let me know if I can assist you further.
     
    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  5. VaL
    VaL avatar
    27 posts
    Member since:
    Oct 2017

    Posted 03 May 2018 in reply to Dimitar Link to this post

    Thanks Dimitar, that works!

    Just one thing: I've seen that when I click on a fieldname on the DataFilter control and the combobox is shown, if I don't select an item but I click somewhere else, the application crashes.

    Here the exception:

    System.NullreferenceExpection
    in Telerik.WinControls.UI.DataFilterCriteriaNode.set_PropertyName(String value)<br>   in Telerik.WinControls.UI.DataFilterCriteriaElement.UpdateDescriptorValue(Object value)<br>   in Telerik.WinControls.UI.RadDataFilterElement.SaveEditorValue(TreeNodeElement nodeElement, Object newValue)<br>   in Telerik.WinControls.UI.RadTreeViewElement.EndEditCore(Boolean commitChanges)<br>   in Telerik.WinControls.UI.RadDataFilterElement.EndEditCore(Boolean commitChanges)<br>   in Telerik.WinControls.UI.RadTreeViewElement.ProcessMouseDown(MouseEventArgs e)<br>   in Telerik.WinControls.UI.RadTreeView.OnMouseDown(MouseEventArgs e)<br>   in System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)<br>   in System.Windows.Forms.Control.WndProc(Message& m)<br>   in System.Windows.Forms.ScrollableControl.WndProc(Message& m)<br>   in Telerik.WinControls.RadControl.WndProc(Message& m)<br>   in Telerik.WinControls.UI.RadTreeView.WndProc(Message& m)<br>   in System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)<br>   in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)<br>   in System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)<br>   in System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)<br>   in System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)<br>   in System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)<br>   in System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)<br>   in System.Windows.Forms.Application.Run(Form mainForm)
  6. Dimitar
    Admin
    Dimitar avatar
    2741 posts

    Posted 03 May 2018 Link to this post

    Hi Valerio,

    Please make sure that the field names in your data source are the same as the keys used in the dictionary.

    If this does not help please open a new support ticket and attach your project there. This will allow us to properly investigate this case and determine what is causing this.

    Should you have any other questions do not hesitate to ask.

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  7. VaL
    VaL avatar
    27 posts
    Member since:
    Oct 2017

    Posted 03 May 2018 in reply to Dimitar Link to this post

    I think I've found the problem...
    Creating the Dictionary I was including also a property having the attribute [Browsable(false)].
    Which was ignored by the DataFilter... from where the "unknown" field.
  8. Dimitar
    Admin
    Dimitar avatar
    2741 posts

    Posted 04 May 2018 Link to this post

    Hi Valerio,

    I am glad that this works fine now. Do not hesitate to contact us if you have other questions.

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  9. Jason Parrish
    Jason Parrish avatar
    92 posts
    Member since:
    Sep 2009

    Posted 21 Aug 2018 in reply to Dimitar Link to this post

    Your code works great.  However, I noticed that when focus is lost or even if the mouse moves off, the text switches back to the fieldname.  thoughts?
  10. Dimitar
    Admin
    Dimitar avatar
    2741 posts

    Posted 22 Aug 2018 Link to this post

    Hi Jason,

    This case is handled by the code in the NodeFormatting event handler. I have tested this again on my side and it works as expected (see attached image). I would recommend submitting a ticket where you can attach your project. This will allow us to properly investigate this.

    Let me know if you have additional questions.

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top