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 rows dynamically in a DataGridView

Adding rows dynamically in a DataGridView

Scheduled Pinned Locked Moved C#
csswinformshelp
3 Posts 3 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 for the DataGridView of Windows Forms and is explained as follows: 1. I have a Quantity textbox in the DataGridView. 2. When the user enter the quantity > 1 (say 3), a total of 3 rows should be added including the current row with the row quantity in all the rows as 1. 3. This should be achieved only when the user hits the Enter key in the current cell. 4. If the row where the quantity being modified is in the middle of the grid, the rows next to the current row should get re-positioned based on the number of new rows added. eg: ProductDesc Qty (TextBox) Compaq Laptop 3 DELL DesktopPC 1 When Enter key is pressed in the quantity textbox (for the product Compaq Laptop), the output in the grid should be as follows: ProductDesc Qty (TextBox) Compaq Laptop 1 Compaq Laptop 1 Compaq Laptop 1 DELL DesktopPC 1 I have tried with a couple of existing events of the DataGridView but I couldn't achieve. Please help me with some suggestions. Thanks.

    Subrahmanyam K

    S A 2 Replies Last reply
    0
    • S Subrahmanyam K

      Hi Friends, I have a requirement for the DataGridView of Windows Forms and is explained as follows: 1. I have a Quantity textbox in the DataGridView. 2. When the user enter the quantity > 1 (say 3), a total of 3 rows should be added including the current row with the row quantity in all the rows as 1. 3. This should be achieved only when the user hits the Enter key in the current cell. 4. If the row where the quantity being modified is in the middle of the grid, the rows next to the current row should get re-positioned based on the number of new rows added. eg: ProductDesc Qty (TextBox) Compaq Laptop 3 DELL DesktopPC 1 When Enter key is pressed in the quantity textbox (for the product Compaq Laptop), the output in the grid should be as follows: ProductDesc Qty (TextBox) Compaq Laptop 1 Compaq Laptop 1 Compaq Laptop 1 DELL DesktopPC 1 I have tried with a couple of existing events of the DataGridView but I couldn't achieve. Please help me with some suggestions. Thanks.

      Subrahmanyam K

      S Offline
      S Offline
      Salogus
      wrote on last edited by
      #2

      Most likely, your DataGridView has a DataTable as data source. In this case you have to only add 3 rows in the DataTable. Rows in the DataGridView will appear automatically.

      1 Reply Last reply
      0
      • S Subrahmanyam K

        Hi Friends, I have a requirement for the DataGridView of Windows Forms and is explained as follows: 1. I have a Quantity textbox in the DataGridView. 2. When the user enter the quantity > 1 (say 3), a total of 3 rows should be added including the current row with the row quantity in all the rows as 1. 3. This should be achieved only when the user hits the Enter key in the current cell. 4. If the row where the quantity being modified is in the middle of the grid, the rows next to the current row should get re-positioned based on the number of new rows added. eg: ProductDesc Qty (TextBox) Compaq Laptop 3 DELL DesktopPC 1 When Enter key is pressed in the quantity textbox (for the product Compaq Laptop), the output in the grid should be as follows: ProductDesc Qty (TextBox) Compaq Laptop 1 Compaq Laptop 1 Compaq Laptop 1 DELL DesktopPC 1 I have tried with a couple of existing events of the DataGridView but I couldn't achieve. Please help me with some suggestions. Thanks.

        Subrahmanyam K

        A Offline
        A Offline
        AFSEKI
        wrote on last edited by
        #3

        If your DataGridView is not databound, DataSource = null in this case, then you can use: DataGridViewRowCollection.Add (Object[]) like: myDGV.Row.Add(new object[] {"Compaq Laptop", 1}); myDGV.Row.Add(new object[] {"Dell DesktopPC", 1}); BUT, before, be sure that your myDGV has 2 columns with appropriate typers to hold and display your values.

        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