Hi all,
I'm trying to customize an item,but I'm stuck, I hope someone could help...
What I need is to show inside my PropertyGrid a value (a string) with a button aside (the typical [...] ).
Clicking the button will open up a custom form, from which a new value can be selected.
So something like the following code, which I've found in another thread:
private void RadPropertyGrid1_EditorRequired(object sender, PropertyGridEditorRequiredEventArgs e)
{
if (e.Item.Name == "DatoStringa")
{
var editor = new PropertyGridBrowseEditor();
var el = editor.EditorElement as RadBrowseEditorElement;
el.DialogType = BrowseEditorDialogType.FolderBrowseDialog;
e.Editor = editor;
}
}
That's fine, but I need a brand new form, not a predefined one.
Is this possible?
Thank you!
9 Answers, 1 is accepted
To be complete...
The value will be inside a combobox. The form will be used only for selecting a value through a refined search.
So you want a combo box with an additional button that opens a form. To achieve this you can use PropertyGridDropDownListEditor and add new RadButtonElement to it. Here is an example:
private
void
RadPropertyGrid1_EditorRequired(
object
sender, Telerik.WinControls.UI.PropertyGridEditorRequiredEventArgs e)
{
if
(e.Item.Name ==
"Text"
)
{
var editor =
new
PropertyGridDropDownListEditor();
var button =
new
RadButtonElement();
button.Text =
"..."
;
button.StretchHorizontally =
false
;
button.Click += Button_Click;
var element = editor.EditorElement
as
BaseDropDownListEditorElement;
element.Children[2].Children.Add(button);
e.Editor = editor;
}
}
private
void
Button_Click(
object
sender, EventArgs e)
{
//show your form here
}
I hope this will be useful. Let me know if you have additional questions.
Regards,
Dimitar
Progress Telerik
Thank you Dimitar for this code, it's really helpful!
Just a question more about this code:
which is the best way to fill this combo with a custom set of string?
Just a question more about this code...
Which is the best way to fill this PropertyGridDropDownListEditor with a set of custom strings (not an enum) ?
Thanks!
I think I've figured it out...
element.Items.Add("ART001");
element.Items.Add("ART002");
element.Items.Add("ART003");
Simple as that!
Indeed this is the way to just add some text items. Another approach would be to bind to a list:
element.DataSource =
new
List<
string
>() {
"Item 1"
,
"Item 2"
,
"Item 3"
};
Should you have any other questions do not hesitate to ask.
Regards,
Dimitar
Progress Telerik
I am doing it as you indicate, but it does not allow me to edit the text.
I have tried with:
element.DropDownStyle = RadDropDownStyle.DropDown;
but it does not work.
Hello, Eusebio,
If I understand your requirement correctly, you need to allow editing the text in the PropertyGridDropDownListEditor. Setting the DropDownStyle property to DropDown is the right way to make the text box editable. Note that the PropertyGridDropDownListEditor accepts only valid values considering the items available in the applied DataSource to the editor.
However, if your requirement is to allow the end-users to enter free input, it has to be added to the DataSource as a valid item. The following help article demonstrates a sample approach for the drop-down editor in RadGridView. In a similar way, this custom behavior can be achieved for RadPropertyGrid as well: https://docs.telerik.com/devtools/winforms/controls/gridview/editors/how-to/allow-end-users-to-add-items-to-dropdownlisteditor
I hope this information helps. If you need any further assistance please don't hesitate to contact me.
Regards,
Nadya
Progress Telerik
Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).