Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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;
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 1-Feb-13 22:49pm
Edited 2-Feb-13 4:25am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,192
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 2 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100