private void SetTextBoxEvent()
{
foreach(DataGridTableStyle ts in dataGrid1.TableStyles)
{
foreach(DataGridColumnStyle ds in ts.GridColumnStyles)
{
DataGridTextBoxColumn tb = ds as DataGridTextBoxColumn;
if (tb != null)
{
tb.TextBox.TextChanged += new EventHandler(GridTextBoxTextChanged);
}
}
}
}
private void GridTextBoxTextChanged(object sender,EventArgs e)
{
TextBox tb = sender as TextBox;
if (tb != null)
{
string str = tb.Text;
if (str.Length == 4)
{
try
{
int.Parse(str);
if (dataGrid1.CurrentCell.ColumnNumber == dataGrid1.TableStyles[0].GridColumnStyles.Count-1)
{
dataGrid1.CurrentCell =
new DataGridCell(
dataGrid1.CurrentCell.RowNumber + 1,0);
}
else
{
dataGrid1.CurrentCell =
new DataGridCell(
dataGrid1.CurrentCell.RowNumber,dataGrid1.CurrentCell.ColumnNumber + 1);
}
}
catch(FormatException) { }
catch(Exception ex)
{
throw ex;
}
}
}
}
|