Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
for (int nCounter = 0; nCounter <= dataGridView1.RowCount - 1; nCounter++)
            {
                if (txtrawmatno.Text == dataGridView1[2, nCounter].Value.ToString())
               {
                    MessageBox.Show("That product has been selected already.", "Repeat", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
 
            }


Can you give a simpler code, or fix this?
Posted
Updated 15-Jul-12 6:57am
v3
Comments
Abdul Quader Mamun 15-Jul-12 15:48pm    
what is the question here?

1 solution

You should take a look at CellValidating. Your loop above has issues because the message box will block the UI which is bad. If you want to use the method above then consider writing each exception / duplicate detail in a string (string builder) and then updating the UI once all rows have been checked. The UI could show this as a summary or something.

Cell validation:
http://msdn.microsoft.com/en-us/library/ykdxa0bc.aspx[^]
 
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