【问题标题】:Allow only specific letters in specific column in RadGridView仅允许 RadGridView 中特定列中的特定字母
【发布时间】:2012-11-24 07:33:03
【问题描述】:

我有一个 RadGridView,我想防止用户在 第五 列中写入除 '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;
    }
}

【问题讨论】:

    标签: c# .net winforms telerik keypress


    【解决方案1】:

    使用下面的代码 sn-p,如果你想做更多的事情,比如提醒用户,或者添加验证错误,这取决于你:

         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;
                    }
                }
            }
        }
    

    【讨论】:

    • @fadddd 如果有效,您可以通过单击答案旁边的复选标记来接受答案,让未来的用户知道它对您有效:)
    猜你喜欢
    • 2019-05-23
    • 2015-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-05
    • 2019-08-12
    相关资源
    最近更新 更多