2017-01-06 5 views
-1

, поэтому у меня есть 3 поля, которые объединяются в 1 строку, и я в настоящее время исправляю проверку, поэтому вопрос заключается в том, как я могу определить определенное пустое содержимое, и пользователю необходимо заполнить его до он/она может продолжить я попробовал это, чтобы показать все поля проверки

if(string.IsNullOrEmpty(txtEYear.Text) || string.IsNullOrEmpty(txtECat.Text) || string.IsNullOrEmpty(txtEID.Text)) 
       { 
        MessageBox.Show("Please fill in the missing fields"); 
       } 
+0

Вы можете поставить индивидуальную проверку. – Prajwal

+0

Итак, вам нужно проверить их отдельно и показать одно сообщение, не так ли? –

+0

Используйте 'if ... elseif .. elseif' –

ответ

1

для этого вы должны использовать отдельную петлю и формируют сообщение что-то вроде этого:

bool isValidated = true; 
StringBuilder message= new StringBuilder("Please fill the following fields: "); 
if(string.IsNullOrEmpty(txtEYear.Text) 
{ 
    message.Append("Year"); 
    isValidated = false; 
} 
if(string.IsNullOrEmpty(txtECat.Text)) 
{ 
    message.Append("txtECat"); 
    isValidated = false; 
} 
if(string.IsNullOrEmpty(txtEID.Text)) 
{ 
    message.Append("ID"); 
    isValidated = false; 
} 

// check all fields are valid 
if(isValidated) 
{ 
    // Continue 
} 
else 
{ 
    MessageBox.Show(message.ToString()); 
}     
1

Попробуйте one.When любой поданной пустой фокус искомая поле.

string message = string.empty; 
message = "Please fill the "; 
if(string.IsNullOrEmpty(txtEYear.Text)) 
    { 
     message = message + " txtEYear "; 
     txtEYear.Focus(); 
    } 
    if(string.IsNullOrEmpty(txtECat.Text)) 
    { 
     message = message + " txtECat"; 
     txtECat.Focus(); 
    } 
    if(string.IsNullOrEmpty(txtEID.Text)) 
    { 
     message = message + " txtEID"; 
     txtEID.Focus(); 
    } 

    MessageBox.Show(message+" Fields"); 
Смежные вопросы