<p>I'm suddenly back to WinForms, after years of web development, and am having trouble  with something that should be simple.  I have an <code>ArrayList</code> of business objects bound to a  Windows Forms <code>DataGrid</code>.  I'd like the user to be able to edit the cells, and when finished,  press a Save button.  At that point I'd like to iterate the all the rows and columns in the  <code>DataGrid</code> to find any changes, and save them to the database.  But I can't find a way to  access the <code>DataGrid</code> rows.  </p>

<p>I'll also want to validate individual cells real time, as they are edited, but I'm pretty  sure that can be done.  (Maybe not with an <code>ArrayList</code> as the <code>DataSource</code>?)  But as for iterating the <code>DataGrid</code>, I'm quite surprised it doesn't seem possible.</p>

<p>Must I really stuff my business objects data into datatables in order to use the datagrid?  </p>

[{'answer_id': 6435, 'author': 'NotMyself', 'author_id': 303, 'author_profile': 'https://Stackoverflow.com/users/303', 'pm_score': 4, 'selected': True, 'text': '<pre class="lang-cs prettyprint-override"><code>foreach(var row in DataGrid1.Rows)\n{\n  DoStuff(row);\n}\n//Or ---------------------------------------------   \nforeach(DataGridRow row in DataGrid1.Rows)\n{\n  DoStuff(row);\n}\n//Or ---------------------------------------------\nfor(int i = 0; i&lt; DataGrid1.Rows.Count - 1; i++)\n{\n  DoStuff(DataGrid1.Rows[i]);\n}\n</code></pre>\n'}, {'answer_id': 6541, 'author': 'Orion Edwards', 'author_id': 234, 'author_profile': 'https://Stackoverflow.com/users/234', 'pm_score': 0, 'selected': False, 'text': "<blockquote>\n  <p>Is there anything about WinForms 3.0 that is so much better than in 1.1</p>\n</blockquote>\n\n<p>I don't know about 3.0, but you can write code in VS 2008 which runs on the .NET 2.0 framework. (So, you get to use the latest C# language, but you can only use the 2.0 libraries)</p>\n\n<p>This gets you Generics (<code>List&lt;DataRow&gt;</code> instead of those GodAwful ArrayLists) and a ton of other stuff, you'll literally end up writing 3x less code.</p>\n"}, {'answer_id': 7491, 'author': 'Mike', 'author_id': 785, 'author_profile': 'https://Stackoverflow.com/users/785', 'pm_score': 1, 'selected': False, 'text': '<pre><code>object cell = myDataGrid[row, col];\n</code></pre>\n'}, {'answer_id': 8421, 'author': 'Mike', 'author_id': 785, 'author_profile': 'https://Stackoverflow.com/users/785', 'pm_score': -1, 'selected': False, 'text': '<p>Aha, I was really just testing everyone once again!  :)  The real answer is, you rarely need to iterate the datagrid.  Because even when binding to an ArrayList, the binding is 2 way.  Still, it is handy to know how to itereate the grid directly, it can save a few lines of code now and then.  </p>\n\n<p>But NotMyself and Orion gave the better answers:  Convince the stakeholders to move up to a higher version of C#, to save development costs and increase maintainability and extensability.</p>\n'}]
['https://Stackoverflow.com/questions/6430', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/785/']