[英]Prevent gridview from losing focus if validation fails
我在實現單元格和行驗證的表單上有一個Telerik radGridView。 沒問題,效果很好。
當我保留一行不完整,然后單擊表單上其他位置的“保存”按鈕時,就會出現問題。 下面的RowValidating代碼段不起作用,因為一旦焦點從gridview移到Save按鈕,則if(row!= null)始終為false,並且永遠不會執行RowValidating代碼。
private void radGridView1_RowValidating(object sender, RowValidatingEventArgs e)
{
var row = e.Row as GridViewDataRowInfo;
if (row != null)
{
var value = row.Cells["cboUnit"].Value.ToString();
if (string.IsNullOrEmpty(value))
{
e.Cancel = true;
row.ErrorText = "Unit Number is a required field";
}
else
{
row.ErrorText = string.Empty;
}
在允許用戶離開網格並保存之前,如何在網格中保持焦點以確保整個網格都有效?
請嘗試同時給出兩個條件。
private void radGridView1_RowValidating(object sender, RowValidatingEventArgs e)
{
var row = e.Row as GridViewDataRowInfo;
var value = row.Cells["cboUnit"].Value.ToString();
if (string.IsNullOrEmpty(value) && row != null)
{
e.Cancel = true;
row.ErrorText = "Unit Number is a required field";
}
else
{
row.ErrorText = string.Empty;
}
我沒有嘗試過代碼,但希望對您有所幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.