c#winform中,textbox控件动态绑定在一个datagridview控件上,在textbox中输入其它字符都正常,但是一旦输入数字0,控件立刻消失,请问这个问题怎么解决?
#region - 单元格点击触发事件 -
private void mDGV_CellClick(object sender, DataGridViewCellEventArgs e)
{
if(e.RowIndex3) return;
Rectangle rect = mDGV.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);
mtxctl = CreatTxCtl(rect);
mtxctl.TextChanged += new EventHandler(Txbox_TextChanged); // 绑定文本改变改变事件
mtxctl.LostFocus += new EventHandler(Txbox_FocusChanged); // 绑定控件失去焦点事件
mDGV.Controls.Add(mtxctl);
mtxctl.Focus();
}
#endregion
#region - 生成控件 -
private TextBox CreatTxCtl(Rectangle rect)
{
TextBox mbox = new TextBox();
mbox.Font = new Font(FontFamily.GenericSansSerif,11.0F,FontStyle.Regular);
mbox.AutoSize = false;
mbox.BorderStyle = BorderStyle.None;
mbox.Text = (mDGV.CurrentCell.Value!=null)?mDGV.CurrentCell.Value.ToString():"";
mbox.Left = rect.Left;
mbox.Top = rect.Top;
mbox.Width = rect.Width-1;
mbox.Height = rect.Height-1;
return mbox;
}
#endregion