Windows Develop Bookmark and Share   
 index > Windows Forms General > How do I loop through a Datagridview control??
 

How do I loop through a Datagridview control??

I have a datagridview control in a vb.net Windows form. I need to add the row(s) of the records to an Access database. I have a function call to add a row of record to the Access tableand it is working fine. How to loop through all the rows in the datagridview control and save the data one by one to the database? Also how do I filter out those row(s) for saving if certain conditions failed as in my case the value on one of the datagridviewtextbox can not be Null. Thanks.
pmak  Friday, July 27, 2007 4:41 PM
Hi

To loop through a DataGridView, try something like this:

Code Snippet

foreachDataGridViewRow dgr in this.dataGridView1.Rows)

{

if (dgr.Cells[0].Value != null)

{

if (dgr.Cells[0].Value.ToString() != "")

{

}

}

}

Hi

To loop through a DataGridView, try something like this:

Code Snippet

foreachDataGridViewRow dgr in this.dataGridView1.Rows)

{

if (dgr.Cells[0].Value != null)

{

if (dgr.Cells[0].Value.ToString() != "")

{

}

}

}

You can use google to search for other answers

Custom Search

More Threads

• Datagridview Scrollbar Style
• Opening the last form open when the application closed
• Controlling one form to another
• group name field in report
• ToolStripMenuItem
• How stay fix my exe file which is executed by Shell command in my VB project
• VS2008 flowpanlelayout inside tablelayoutpanel has no columnspan property
• Dataset with multiple relationships and combo boxes
• OpenFileDialog usage when application run in server drive
• Changing BackgroundImage 2nd time doesn't work properly with transparency