Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 21:09pm
Edited 1-Feb-13 21:10pm
(no name)43.4K
v2
Comments
jibesh at 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 at 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
0 Maciej Los 184
1 Sergey Alexandrovich Kryukov 154
2 Sascha Lefévre 120
3 Abhinav S 104
4 Jörgen Andersson 75
0 Sergey Alexandrovich Kryukov 6,628
1 OriginalGriff 6,298
2 Peter Leow 2,534
3 Maciej Los 2,437
4 Abhinav S 2,378


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