RC
Rajadurai C
Syncfusion Team
May 20, 2009 12:59 PM UTC
Hi Brian,
Thanks for your interest in Syncfusion products.
With NumericUpDown celltype in gridgroupingcontrol, you can prevent user from entering any invalid entries into the cell by handling some validations manually. Please refer to the following code snippet, in which TableControlCurrentCellChanged and TableControlCurrentCellKeyPress events are handled to do such validations.
//TableControlCurrentCellChanged event
void gridGroupingControl1_TableControlCurrentCellChanged(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlEventArgs e)
{
GridCurrentCell cc = e.TableControl.CurrentCell;
if (cc.Renderer is GridNumericUpDownCellRenderer)
{
GridNumericUpDownCellRenderer rend = cc.Renderer as GridNumericUpDownCellRenderer;
if (rend != null && rend.ControlText != "")
{
int val = int.Parse(rend.ControlText);
if (val < min || val > max)
{
cc.EndEdit();
rend.ControlText = value.ToString();
this.gridGroupingControl1.TableModel[cc.RowIndex, cc.ColIndex].Text = value.ToString();
}
else
value = int.Parse(rend.ControlText);
}
}
}
//initialization part
int min=0, max=20, value = 0;
//TableControlCurrentCellKeyPress event
void gridGroupingControl1_TableControlCurrentCellKeyPress(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlKeyPressEventArgs e)
{
GridCurrentCell cc = e.TableControl.CurrentCell;
if (cc.Renderer is GridNumericUpDownCellRenderer)
{
GridNumericUpDownCellRenderer rend = cc.Renderer as GridNumericUpDownCellRenderer;
if (!(e.Inner.KeyChar == '1' || e.Inner.KeyChar == '2' || e.Inner.KeyChar == '3' || e.Inner.KeyChar == '4' || e.Inner.KeyChar == '5' || e.Inner.KeyChar == '6' || e.Inner.KeyChar == '7' || e.Inner.KeyChar == '8' || e.Inner.KeyChar == '9' || e.Inner.KeyChar == '0'))
{
e.Inner.Handled = true;
}
}
}
//QueryCellStyleInfo event
void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e)
{
if (e.TableCellIdentity.DisplayElement.Kind == DisplayElementKind.Record && e.TableCellIdentity.ColIndex > 0 )
{
e.Style.CellType = "NumericUpDown";
e.Style.HorizontalAlignment = GridHorizontalAlignment.Right;
e.Style.NumericUpDown = new GridNumericUpDownCellInfo(min,max, 5, 1, false);
e.Style.ShowButtons = GridShowButtons.ShowCurrentCell;
}
}
Regards,
Rajadurai