Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Studio
  4. DataGridView, how to insert row when EnterKey pressed

DataGridView, how to insert row when EnterKey pressed

Scheduled Pinned Locked Moved Visual Studio
questioncsharpdatabasevisual-studiohelp
1 Posts 1 Posters 11 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dragon52
    wrote on last edited by
    #1

    Hi, I have a data bounded DataGridView control. When I have filled in a row of data on the control I want to save that data to my database table. I want to do the save by hitting the Enter key. Not using a button control. I have several questions .... 1. How do I trap/detect the Enter key? Do I use KeyPress event like this ? ...

        private void transactionstblDataGridView\_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                transactionstblTableAdapter.Insert(int,DateTime,decimal,decimal,string,int)
                {
                     ///
                };
            }
        }
    

    2. The Adapter.Insert() function in the above is created by Visual Studio. The function parameters list every column of my database table. Two of them are not needed for an Insert/Save because it is defined as auto_increment or as current DateTime (ie use as time_stamp). What do I have to do? How do I do the insert with some parameters left out. Define my own Insert function? 3. How I do detect/know which row on the DataGridView control contains the data I need to save to the database. And thinking ahead, I will do Update, Delete too using the same DataGridView control. Any help is much appreciated Thanks

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups