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. C#
  4. Adding new rows to DataGridView UI in DataBound Mode

Adding new rows to DataGridView UI in DataBound Mode

Scheduled Pinned Locked Moved C#
designjsonquestion
2 Posts 2 Posters 0 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.
  • S Offline
    S Offline
    Subrahmanyam K
    wrote on last edited by
    #1

    Hi Friends, I have a requirement to add new rows to the DataGridView UI which is bound to a DataTable. The new row added to the UI should get added to the underlying DataSource. I have bound the DataGridView to a DataSource. The DataSource consists of 10 columns out of which only 5 columns were bound to the DataGridView. The other 5 columns which are not bound consists of composite primary key on 2 columns and 3 other columns will not accept null values. I have tried with "DefaultValueNeede" event of the DataGridView to define the default values for the new row. As only 5 columns are bound to the DataGridView, I could supply the default values only to those columns. How would I supply the default values to the rest of the columns which are not bound to the DataGridView? Which event of the DataGridView should be handled in this scenario? An exception is thrown when I tried to commit the new row in the DataGridView UI (by adding a "new new row") to the DataGrid. The exception is that "Required values are not supplied to the new DataRow" which are the composite primary key columns (2) and not null columns (3). Thanks.

    Subrahmanyam K

    L 1 Reply Last reply
    0
    • S Subrahmanyam K

      Hi Friends, I have a requirement to add new rows to the DataGridView UI which is bound to a DataTable. The new row added to the UI should get added to the underlying DataSource. I have bound the DataGridView to a DataSource. The DataSource consists of 10 columns out of which only 5 columns were bound to the DataGridView. The other 5 columns which are not bound consists of composite primary key on 2 columns and 3 other columns will not accept null values. I have tried with "DefaultValueNeede" event of the DataGridView to define the default values for the new row. As only 5 columns are bound to the DataGridView, I could supply the default values only to those columns. How would I supply the default values to the rest of the columns which are not bound to the DataGridView? Which event of the DataGridView should be handled in this scenario? An exception is thrown when I tried to commit the new row in the DataGridView UI (by adding a "new new row") to the DataGrid. The exception is that "Required values are not supplied to the new DataRow" which are the composite primary key columns (2) and not null columns (3). Thanks.

      Subrahmanyam K

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      Subrahmanyam K wrote:

      I have tried with "DefaultValueNeede" event of the DataGridView

      Why? Are you following some book, article or tutorial? If not CodeProject very likely has one or more articles that cover this topic.

      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