Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / October 2005

Tip: Looking for answers? Try searching our database.

Copy and Paste rows in DataGridView

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Techstudent - 24 Oct 2005 18:33 GMT
If any one knows how to implement functionality to copy(ctrl+c) an existing
row and paste(ctrl+v) the contents to create a new row in Datagrid view.

I know ctrl+c copies the content to the clipboard, i want "ctrl + v" to
insert the copied contents into a new row.

Any suggestions are appreciated.

Thanks
Sanjeevakumar Hiremath - 31 Oct 2005 09:50 GMT
Try this code.. you need to override WndProc in your own custom datagrid
control. Hope this helps.

 protected override void WndProc(ref Message m)
 {
  IDataObject clipData = Clipboard.GetDataObject();
  bool ctrlDown = false;
  bool shiftDown = false;
  bool handledMessage = false; // used to decide if call to base WndProc
needed.
  switch ( m.Msg )
  {
   case 0x0100 :
   {
    if((int)m.WParam == 0x0011)
    {
     ctrlDown = true;
     break;
    }
    if((int)m.WParam == 0x0010)
    {
     shiftDown = true;
     break;
    }
    if((ctrlDown == true) && ((int)m.WParam == 0x0056))
    {
     handledMessage = PerformPaste();
     break;
    }
    if((shiftDown == true) && ((int)m.WParam == 0x002D))
    {
     handledMessage = PerformPaste();
     break;
    }
   }
    break;
   case 0x0101 :
   {
    if((int)m.WParam == 0x0011)
    {
     ctrlDown = false;
     break;
    }
    if((int)m.WParam == 0x0010)
    {
     shiftDown = false;
     break;
    }
   }
    break;
   case 0x0302 :
   {
    handledMessage = PerformPaste();
   }
    break;
  }
  if(handledMessage == true)
  {
   m.Result = new IntPtr( 0 );
  }
  else
  {
   base.WndProc(ref m);
  }
 }

 private bool PerformPaste()
 {
  //custom past operation implementated by user
 }
Signature

Regards,
Sanjeevakumar Hiremath
Proteans Software Solutions
http://sharpnet.blogspot.com

> If any one knows how to implement functionality to copy(ctrl+c) an
> existing
[quoted text clipped - 6 lines]
>
> Thanks

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.