Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:-
C#
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;


please help me.

Thanks in Advance.
Ankit Agarwal
Software Engineer
Posted
Comments
Krunal Rohit 20-Mar-14 3:14am    
Make your question more clear.

-KR
[no name] 20-Mar-14 3:16am    
I want to run foreach loop from starting every time after compare value true.
Now my foreach value did not run from starting row or first row after compare.
jaideepsinh 20-Mar-14 3:20am    
Can you explain in brief exactly what you want to do And what problem you are facing in your code?
[no name] 20-Mar-14 3:27am    
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.

Try this :

C#
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;
 
Share this answer
 
Comments
[no name] 20-Mar-14 3:45am    
error is coming in if (row.ItemIndex > 0)
jaideepsinh 20-Mar-14 8:23am    
what error it will through?
SQL
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;

}
                    }
                }
           }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900