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
9 Answers, 1 is accepted
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
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!
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.
Dimitar
Progress Telerik
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)
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
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.
I am glad that this works fine now. Do not hesitate to contact us if you have other questions.
Regards,
Dimitar
Progress Telerik
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