首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

datagridview 中TextBox列。输入自动提示。解决办法

2012-04-20 
datagridview 中TextBox列。输入自动提示。C# winform datagridview 中TextBox列。输入自动提示。并且禁止输入

datagridview 中TextBox列。输入自动提示。
C# winform datagridview 中TextBox列。输入自动提示。并且禁止输入数字。请高手指教。

[解决办法]
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) 

dataGridView1.Rows[e.RowIndex].ErrorText = string.Empty; 
if(dataGridView1.Columns[e.ColumnIndex].DataPropertyName == "A") 

Regex rx = new Regex(@"^[1-9]\d*$", RegexOptions.Compiled);
if (rx.IsMatch(e.FormattedValue.ToString()))
{ dataGridView1.Rows[e.RowIndex].ErrorText = "输入有误!"; 
e.Cancel = true; }




private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) 

dataGridView1.Rows[e.RowIndex].ErrorText = string.Empty; 


[解决办法]
给你个比较好用的

C# code
public DataGridViewTextBoxEditingControl CellEdit = null;                  private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)        {            CellEdit = (DataGridViewTextBoxEditingControl)e.Control;                    CellEdit.ShortcutsEnabled = false;            CellEdit.KeyPress += new KeyPressEventHandler(CellEdit_KeyPress);        }        private void CellEdit_KeyPress(object sender, KeyPressEventArgs e)        {           if (Char.IsNumber(e.KeyChar))            {               e.Handled = true;               MessageBox.show("Num forbiden");           }        } 

热点排行