7 Answers, 1 is accepted
You can restrict the spin editor when processing the EditorRequired event in RadGridView. Consider the following code snippet:
void radGridView1_EditorRequired(object sender, EditorRequiredEventArgs e) |
{ |
GridSpinEditor editor = e.Editor as GridSpinEditor; |
if (editor != null) |
{ |
editor.MinValue = 0; |
} |
} |
If you have any other questions, I will be glad to answer them.
All the best,
Jack
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

It seems to me that the solution you give does not work.
Using the debugger, I can see that the Editor property of the event argument gives null.
I found a way to achieve setting the min and max of the GridSpinEditor using the ActiveEditor property of the RadGridView instance :
GridSpinEditor editor = this.radGridView1.ActiveEditor as GridSpinEditor; |
if (editor != null) |
{ |
editor.MinValue = Decimal.Zero; |
editor.MaxValue = 1000m; |
} |
I think this could be helpful.
Thanks
Bye
In 2009 we changed the behavior of EditorRequired event. You should handle this event when you want to replace the default editor with a custom one.
In order to customize editor properties you have to handle CellBeginEdit or CellEditorInitialized events. More details are available in our online help.
Currently you don't need to handle an event at all. You can set the Minimum and Maximum properties of GridViewDecimalColumn. Here is a sample:
GridViewDecimalColumn decimalColumn = (GridViewDecimalColumn)
this
.radGridView1.Columns[
"Value"
];
decimalColumn.Minimum = 5;
decimalColumn.Maximum = 120;
I hope this helps.
Kind regards,
Jack
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.

i want to restrict the editable columns to non negative values.
need help
Thanks.!!
Thank you for writing.
RadGridView does not have "int type column", it has GridViewDecimalColumn which can be bound to fields of any numeric type. You can read more about this column and how to use it here.
To achieve only positive integer numbers, you just need to set the decimal column DataType to int and set the desired minimum:
GridViewDecimalColumn myDecimalColumn = (GridViewDecimalColumn)radGridView1.Columns[
"MyDecimalColumn"
];
myDecimalColumn.DataType =
typeof
(
int
);
myDecimalColumn.Minimum = 0;
However, if you are using some other kind of column like GridViewTextBoxColumn and you want the text to be a non negative numeric value, you can use the ValueChanging event to prevent entering of negative values or the CellValidating event to prevent users to leave the cell until the the value in the cell is not valid.
You can find more info about validation in this article here.
I hope you find this information useful.
Regards,
Anton
Telerik

Thank you for writing.
In order to restrict the user to enter '-' sign in the grid editor, you can handle the KeyPress event of the hosted textbox and set the Handled property to true:
public
Form1()
{
InitializeComponent();
GridViewDecimalColumn decimalColumn =
new
GridViewDecimalColumn();
radGridView1.MasterTemplate.Columns.Add(decimalColumn);
for
(
int
i = 0; i < 10; i++)
{
this
.radGridView1.Rows.Add(i);
}
this
.radGridView1.CellEditorInitialized += radGridView1_CellEditorInitialized;
}
private
void
radGridView1_CellEditorInitialized(
object
sender, GridViewCellEventArgs e)
{
GridSpinEditor editor = e.ActiveEditor
as
GridSpinEditor;
if
(editor !=
null
)
{
GridSpinEditorElement el = editor.EditorElement
as
GridSpinEditorElement;
el.TextBoxItem.HostedControl.KeyPress+=HostedControl_KeyPress;
}
}
private
void
HostedControl_KeyPress(
object
sender, KeyPressEventArgs e)
{
if
(e.KeyChar == 45)
{
e.Handled =
true
;
}
}
I hope this information helps. Should you have further questions I would be glad to help.
Dess
Telerik