Click here to Skip to main content
13,201,940 members (75,772 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
private void dataGridViewTextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
 
   private String CopyString;
 
 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;
                }
                }



run time output as follows;

Date session CM GS NR VB PN SK

1/2/2013 1 REo Tasco PH2 PH2

using shortcut key copy the PH2 course and paste in the VB Column. that time message shows ok.

before pasting message shows ok why?

when user paste the same data in to the next column. that i want to show the message the course is already allocated do you want to continue.


from my above code what is the mistake. help me.

for pasting the record in datagridview using short cut key i use the

(e.KeyChar == 118 || e.KeyChar == 86) code.

help me.
Posted 1-Feb-13 20:09pm
Updated 1-Feb-13 20:10pm
v2
Comments
jibesh 2-Feb-13 3:44am
   
try using the datagridview CellValidate and CellValueChange event. I saw you were struggling to get this for the past few days, I might try this for you soon.
Member 8054539 2-Feb-13 8:43am
   
please reply question and update the answer

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web03 | 2.8.171020.1 | Last Updated 2 Feb 2013
Copyright © CodeProject, 1999-2017
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