错误消息应该只出现一次。但它在循环方面有效。帮助我这个,而不是提前X. [英] error msg should apear only one time. but it is working with respect to loop. help me with this, thanX in Advance.

查看:54
本文介绍了错误消息应该只出现一次。但它在循环方面有效。帮助我这个,而不是提前X.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int i = dataGridView1.Rows.Count;
           for (i = 0; i <= dataGridView1.Rows.Count - 1; i++)
           {
               if (dataGridView1.Rows[i].Cells[1].Value.ToString() == txtcscnic1.Text + "-" + txtcscnic2.Text + "-" + txtcscnic3.Text)
               {
                   dataGridView1.Rows[i].Selected = true;
               }
               else
               {
                   MessageBox.Show("Customer with CNIC'" + txtcscnic1.Text + "-" + txtcscnic2.Text + "-" + txtcscnic3.Text + "' does not Exist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
               }
           }

推荐答案

只需进行此修改,您的MessageBox只会出现一次。

Just make this modification and your MessageBox will only appear once.
int i = dataGridView1.Rows.Count;
bool itemFound = false;
for (i = 0; i <= dataGridView1.Rows.Count - 1; i++)
{
   if (dataGridView1.Rows[i].Cells[1].Value.ToString() == txtcscnic1.Text + "-" + txtcscnic2.Text + "-" + txtcscnic3.Text)
   {
      dataGridView1.Rows[i].Selected = true;
      itemFound = true;
      break;
   }   
}
if( !itemFound )
{
   MessageBox.Show("Customer with CNIC'" + txtcscnic1.Text + "-" + txtcscnic2.Text + "-" + txtcscnic3.Text + "' does not Exist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}


首先从中删除​​循环的消息框。 />


接下来尝试构建一个字符串(最好使用 stringbuilder ),其中包含所有错误的客户代码。

最后在for循环外的消息框中显示。
First thing remove the message box out of the for loop.

Next try to build a string (preferablly using stringbuilder) that contains all customer codes with error.
Finally display this in the message box outside the for loop.


这篇关于错误消息应该只出现一次。但它在循环方面有效。帮助我这个,而不是提前X.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆