Hi,
I am evaluating your WinForms control suite to see if I could use it for a project I'm working on. I'm trying to create a custom editor in a GridView that would allow me to have a searchable ComboBox where the users can add/rename items right from the editor. First I tried to add an element while in edit mode based on an forum thread I saw (I added a TextBox in addition to the combobox) but I cannot get it to allow focus on the textbox in addition to the ComboBox. Is there a better way to achieve having a ComboBox AND TextBox together in the same editor? Or do you have a better idea of how I could achieve the user story of allowing the user to add/rename items from the ComboBox right from the grid without having another form? From what I'm seeing it looks like the GridBaseEditor just allows one EditorElement not two. Any help you could provide would be appreciated.
Thank you for your time.
5 Answers, 1 is accepted
Thank you for writing.
Following the provided information I have prepared a sample project for your reference which result is illustrated in the attached gif file. Note that this is just a sample approach and it may not cover all possible cases. Feel free to modify it in a way which suits your requirement best.
I hope this information helps. Should you have further questions I would be glad to help.
Regards,
Dess
Progress Telerik
Hi,
I am evaluating your WinForms control suite to see if I could use it for a project I'm working on. I'm trying to create a custom editor in a GridView.
One column of my GridView contains a currency formatted decimal (the price of the product). I would like that when I edit this data, a custom editor appears with a RadSpinEditor to allow me to enter a new value and severals RadLabel contains with informations (see attachment).
However, I don't understand how it works.
Can you help me ?
Is it posible to arrange controls in a custom editor with a layout control ?
Thank you for your time.
Fabrizio
I have prepared a sample code snippet demonstrating how to construct a custom currency editor that contains a spin editor and two text elements as it is illustrated below:
public
RadForm1()
{
InitializeComponent();
BindingList<Item> items =
new
BindingList<Item>();
for
(
int
i = 1; i <= 3; i++)
{
items.Add(
new
Item(i,
"Item"
+ i, 1.25m * i));
}
this
.radGridView1.DataSource = items;
this
.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
this
.radGridView1.EditorRequired += radGridView1_EditorRequired;
}
private
void
radGridView1_EditorRequired(
object
sender, Telerik.WinControls.UI.EditorRequiredEventArgs e)
{
if
(
this
.radGridView1.CurrentColumn.Name ==
"Price"
)
{
e.EditorType =
typeof
(MyCustomCurrencyEditor);
}
}
}
public
class
MyCustomCurrencyEditor : BaseGridEditor
{
protected
override
Telerik.WinControls.RadElement CreateEditorElement()
{
return
new
CustomSpinEditorElement();
}
public
override
object
Value
{
get
{
CustomSpinEditorElement element =
this
.EditorElement
as
CustomSpinEditorElement;
return
element.SpinEditorElement.Value;
}
set
{
CustomSpinEditorElement element =
this
.EditorElement
as
CustomSpinEditorElement;
element.SpinEditorElement.Value = (
decimal
)value;
}
}
public
override
void
BeginEdit()
{
base
.BeginEdit();
CustomSpinEditorElement element =
this
.EditorElement
as
CustomSpinEditorElement;
element.SpinEditorElement.DecimalPlaces = 2;
element.SpinEditorElement.TextBoxControl.Focus();
}
}
public
class
CustomSpinEditorElement : RadTextBoxEditorElement
{
StackLayoutElement stack =
new
StackLayoutElement();
RadSpinEditorElement spinEditorElement =
new
RadSpinEditorElement();
LightVisualElement text1 =
new
LightVisualElement();
LightVisualElement text2 =
new
LightVisualElement();
public
CustomSpinEditorElement()
{
this
.TextBoxItem.Visibility = ElementVisibility.Collapsed;
this
.Padding =
new
Padding(0);
}
public
RadSpinEditorElement SpinEditorElement
{
get
{
return
this
.spinEditorElement;
}
}
protected
override
void
CreateChildElements()
{
base
.CreateChildElements();
stack.Margin =
new
System.Windows.Forms.Padding(0);
stack.StretchHorizontally =
true
;
stack.StretchVertically =
true
;
stack.Orientation = Orientation.Horizontal;
stack.Children.Add(spinEditorElement);
stack.Children.Add(text1);
text1.Text =
"Text1"
;
text2.Text =
"Text2"
;
stack.Children.Add(text2);
this
.Children.Add(stack);
}
}
public
class
Item
{
public
int
Id {
get
;
set
; }
public
string
Name {
get
;
set
; }
public
decimal
Price {
get
;
set
; }
public
Item(
int
id,
string
name,
decimal
price)
{
this
.Id = id;
this
.Name = name;
this
.Price = price;
}
}
Note that this is just a sample approach and it may not cover all possible cases. Feel free to extend it in a way which suits your requirement best.
Off topic, I will recommend you to activate a 30-day free trial, giving you some time to explore the toolkit and consider using it for your current or upcoming WinForms development.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Thank you.
If I replace in your code the two LightVisualElement control in the CustomSpinEditorElement class, by a RadDropdownButtonElement, the dropDownListElement and the spinEditorElement in the StackLayoutElement are the same width. Can you tell me if is it possible to set the size of the DropdownButtonElement and to dock it at right and the spinEditorElement dock fill ?
Thank you
You can disable the horizontal stretching of the RadDropDownButtonElement and specify its MinSize. Thus, the RadSpinEditorElement will stretch horizontally to fill the space:
public
class
CustomSpinEditorElement : RadTextBoxEditorElement
{
StackLayoutElement stack =
new
StackLayoutElement();
RadSpinEditorElement spinEditorElement =
new
RadSpinEditorElement();
RadDropDownButtonElement text1 =
new
RadDropDownButtonElement();
public
CustomSpinEditorElement()
{
this
.TextBoxItem.Visibility = ElementVisibility.Collapsed;
this
.Padding =
new
Padding(0);
}
public
RadSpinEditorElement SpinEditorElement
{
get
{
return
this
.spinEditorElement;
}
}
protected
override
void
CreateChildElements()
{
base
.CreateChildElements();
stack.Margin =
new
System.Windows.Forms.Padding(0);
stack.StretchHorizontally =
true
;
stack.StretchVertically =
true
;
stack.Orientation = Orientation.Horizontal;
stack.Children.Add(spinEditorElement);
stack.Children.Add(text1);
text1.Text =
"Text1"
;
text1.StretchHorizontally =
false
;
text1.MinSize =
new
System.Drawing.Size(60,18);
this
.Children.Add(stack);
}
}
I hope this information helps. If you need any further assistance please don't hesitate to contact me.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik