不好意思,回复晚了。
请确保你已经在Template当中给Cell设置了MaxLength为6.
然后,请看下面的代码:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.gcMultiRow1.CellFormatting += gcMultiRow1_CellFormatting;
this.gcMultiRow1.EditingControlShowing += gcMultiRow1_EditingControlShowing;
}
void gcMultiRow1_EditingControlShowing(object sender, GrapeCity.Win.MultiRow.EditingControlShowingEventArgs e)
{
if (this.gcMultiRow1.CurrentCellPosition.CellName == "textBoxCell1")
{
TextBox textBox = e.Control as TextBox;
if (e.Control.Text.Length > textBox.MaxLength)
{
int removeLength = e.Control.Text.Length - textBox.MaxLength;
e.Control.Text = e.Control.Text.Remove(textBox.MaxLength, removeLength);//确保编辑状态为6位。
}
}
}
void gcMultiRow1_CellFormatting(object sender, GrapeCity.Win.MultiRow.CellFormattingEventArgs e)
{
if (e.CellName == "textBoxCell1")
{
if (e.Value != null)
{
e.Value = e.Value + "12";//增加两位
}
}
}
} |