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