Click here to Skip to main content
11,795,848 members (82,905 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# DataGridView WinForm
I have a DataGridView which has 1 column. I want the user to add as many rows they need. Then when they move onto the next tab the rows are saved. At the moment the user enters the data and can move to next tab and if they go back the data is still there. However when I try to save the data when they leave the tab, the row count for the DataGridView is 0. Therefore not entering the foreach statement where I try get the cell data from.

My code for when I try to get the data is-
foreach (DataRow row in gv_mullionList.Rows)
  //never gets this far
  //would set cell value to an object

Why do I need to do to get the rows?
Posted 25-Mar-13 6:16am
CHill60 at 25-Mar-13 12:29pm
Where are you putting the code with the foreach ? (specifically which event I mean)
Richard MacCutchan at 25-Mar-13 12:37pm
Add an event handler for the condition you wish to capture. This could be adding a row or ending the edit of a cell. In either case that is the point at which to check the content of any new cell in the grid.
rk_2010 at 27-Mar-13 3:23am
You can add the user entered values into a datatable and persist the datatable in viewstate or session. Just bind gridview whenever needed.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1[^]Please try this link.Here when user enters all the information he can save the data after doing the entry.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 410
1 Abhinav S 368
2 OriginalGriff 300
3 Sergey Alexandrovich Kryukov 266
4 KrunalRohit 249
0 OriginalGriff 1,852
1 Maciej Los 1,465
2 KrunalRohit 1,300
3 CPallini 840
4 Richard MacCutchan 828

Advertise | Privacy | Mobile
Web01 | 2.8.151002.1 | Last Updated 27 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100