如何在c#.net中比较之后每次启动foreach循环? [英] How to run foreach loop from starting every time after compare in c# .net?

查看:62
本文介绍了如何在c#.net中比较之后每次启动foreach循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



如何在c#.net比较后每次启动运行foreach循环?



我想搜索datagridview windows应用程序中的每一行值,如果条件是

fter,

我的代码是: -

Hello,

How to run foreach loop from starting every time after compare in c# .net?

I want to search every row of value in datagridview windows application, a
fter if condition,
My code is:-

int KreationSeq = 0;
            KreationSeq++;
            string TempID = "Customized Kreation Wardrobe " + KreationSeq;

            foreach (DataGridViewRow row in DGVCurrentConfiguration.Rows)
            {

                if (row.Cells[0].Value.ToString() == TempID)
                {
                    //KreationSeq++;
                    KreationSeq++;
                    TempID = "Customized Kreation Wardrobe " + KreationSeq;
                    //UUSKreationItemCount = KreationSeq;
                }
            }
            UUSKreationItemCount = KreationSeq;





请帮帮我。



谢谢提前。

Ankit Agarwal

软件工程师



please help me.

Thanks in Advance.
Ankit Agarwal
Software Engineer

推荐答案

试试这个:



Try this :

int KreationSeq = 0;
    KreationSeq++;
    string TempID = "Customized Kreation Wardrobe " + KreationSeq;

            foreach (DataGridViewRow row in DGVCurrentConfiguration.Items)

    {
        if (row.ItemIndex > 0)
        {
            if (row.Cells[ColumnIndex].Text == TempID)
            {
        //KreationSeq++;
                KreationSeq++;
                TempID = "Customized Kreation Wardrobe " + KreationSeq;
                //UUSKreationItemCount = KreationSeq;
            }
        }
    }
    UUSKreationItemCount = KreationSeq;


As per your required
"I want to search value in every column but my code is break after if condition true,
I want to search value every time from starting."
See the following code
 foreach (DataGridViewRow row in DGVCurrentConfiguration.Rows)
             {
                 foreach (DataGridViewCell cell in row.Cells)
                {
                    if (cell.ColumnIndex == 0) //SET YOUR PARTICULAR COLUMN INDEX HERE!!
                    {
                         if (cell.FormattedValue != String.Empty && cell.FormattedValue==TempID) 
{
 //KreationSeq++;
                    KreationSeq++;
                    TempID = "Customized Kreation Wardrobe " + KreationSeq;
                    //UUSKreationItemCount = KreationSeq;

}
                    }
                }
           }


这篇关于如何在c#.net中比较之后每次启动foreach循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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