Code Block
private void frmteste_Load(object sender, EventArgs e)
{
// Cria a coluna no dataGridview
this.dataGridView1.Columns.Add("DtVencto", "Vencimento");
this.dataGridView1.Columns["DtVencto"].DataPropertyName = "DTVENCIMENTO";
// cria o controle e adiciona ao DatagridView.
this.maskedTextBox = new MaskedTextBox();
this.maskedTextBox.Visible = false;
this.dataGridView1.Controls.Add(this.maskedTextBox);
// Adiciona o envento que controla a edição da célula..
this.dataGridView1.CellBeginEdit += new DataGridViewCellCancelEventHandler(dataGridView1_CellBeginEdit);
}
void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
if (e.ColumnIndex == this.dataGridView1.Columns["DtVencto"].Index &&
e.RowIndex <
this.dataGridView1.NewRowIndex)
{
this.maskedTextBox.Mask = "00/00/0000";
Rectangle rect = this.dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);
this.maskedTextBox.Location = rect.Location;
this.maskedTextBox.Size = rect.Size;
this.maskedTextBox.Text = "";
if (this.dataGridView1[e.ColumnIndex, e.RowIndex].Value != null)
{
this.maskedTextBox.Text = this.dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();
}
this.maskedTextBox.Visible = true;
// Aqui tento direcionar o foco..
this.maskedTextBox.Focus();
}
}