Click here to Skip to main content
Rate this: bad
good
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 7:16am
Comments
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
good
Please Sign up or sign in to vote.

Solution 1

http://www.c-sharpcorner.com/UploadFile/ANURAGSARKAR19/saving-data-using-datagridview-and-doing-calculations/[^]Please try this link.Here when user enters all the information he can save the data after doing the entry.
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 386
1 Marcin Kozub 225
2 Sergey Alexandrovich Kryukov 215
3 /\jmot 189
4 Praneet Nadkar 173
0 OriginalGriff 8,289
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,624
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 27 Mar 2013
Copyright © CodeProject, 1999-2014
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