分三步:
第一步:
private void Grid1_EnterCell(object sender, EventArgs e)//使文本框可见
{
if (Grid1.ColSel > 1)
{
iRow = Grid1.RowSel;
txt.Text = Grid1.get_TextMatrix(Grid1.RowSel, Grid1.ColSel);
txt.SelectAll();
txt.Visible = true;
txt.Left = Grid1.CellLeft / 15;
txt.Top = Grid1.CellTop / 15;
txt.Height = Grid1.CellHeight / 15;
txt.Width = Grid1.CellWidth / 15;
txt.ForeColor = Grid1.ForeColor;
txt.BackColor = Grid1.BackColor;
txt.Focus();
}
}
第二步:
private void txt_TextChanged(object sender, EventArgs e)//表格内容随文本框更改而更改
{
Grid1.Row = iRow;
Grid1.set_TextMatrix(iRow, Grid1.ColSel, txt.Text);
}
第三步:
private void txt_KeyPress(object sender, KeyPressEventArgs e) //回车,确定输入完毕
{
if (e.KeyChar == 13)
{
txt.Top = txt.Top + Grid1.CellHeight / 15 + 1;
iRow++;
txt.Text = "";
}
}
浙公网安备 33010602011771号