Click here to Skip to main content
15,885,740 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to validate repeated values in each cell using datagridivew in csharp. how to validate and show the pop up message. i validate but it is not working.please help me.
my code as follows;
C#
if (e.KeyChar == 118 || e.KeyChar == 86)// v,V to paste
                {
                    String Msg = "";
                    if (CopyString != "" && CopyString != null)
                    {
                        int irow = Convert.ToInt16(datagridView.CurrentCellAddress.Y.ToString());
                        for (int i = 2; i < datagridView.Columns.Count; i++)
                        {
                            if (datagridView[i, irow].Value != "" && datagridView[i, irow].Value != null)
                            {
                                if (datagridView[i, irow].Value.ToString().Trim() == CopyString.ToString().Trim())
                                {
                                    Msg = "Course is already entered in " + datagridView.Columns[i].HeaderText;
                                }
                            }
                        }
                        //if (Msg.ToString() != null)
                        //{
                        //    MessageBox.Show(Msg.ToString());
                        //}
                        //else
                        {
                            datagridView.CurrentCell.Value = CopyString.ToString();
                        }
                    }
                    e.Handled = true;
                }

from my above code what is the mistake help me.
Posted
Updated 2-Feb-13 3:25am
v2

1 solution

Before you enter the data in the DataGridView, from your source eliminate the duplicate requests. If the requests are saved in a List then use the Linq statement Distinct to take distinct values only and insert them in the DataSource of the DataGridView.
 
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