我有一个 RadGridView,我想阻止用户在 fifth 列中写入除 'c' 或 'd' 以外的任何字符、数字或字母。 我试过下面的代码,但没有用...
private void radGridView1_KeyPress(object sender, KeyPressEventArgs e)
{
if (radGridView1.CurrentColumn.Index == 4)
{
if (e.KeyChar != 'c' || e.KeyChar != 'd' )
e.Handled = true;
}
}
最佳答案
使用下面的代码片段,如果你想做更多的事情,比如提醒用户,或者添加一个验证错误,这取决于你:
private void radGridView1_CellValidating(object sender, CellValidatingEventArgs e)
{
String[] Acceptable = new string[] {"c", "d"};
if (e.Value != null && e.ColumnIndex == 4)
{
if(e.Value != e.OldValue)
{
if (!Acceptable.Contains(e.Value))
{
e.Cancel = true;
}
}
}
}
关于c# - 仅允许 RadGridView 中特定列中的特定字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13539294/