iterate over datagrid
-
I have a datagrid with this structure: Column1 Column2 Column3 Name URL FilePathtoSaveTo There are 1000 rows in the grid and I want to use the url (Column2) in an httpwebrequest and httpwebresponse to get web pages and then use the FilePathtoSaveTo (Column3) to write the web page to disk. Anyone know of a foreach loop (or some other way) that will allow me to do this (return the cell values from columns 2 and 3 in order to be used as variables for my web request and write?) Thanks, Paul (Also, the urls return text files that when saved with the .html extension, open as html files.)
-
I have a datagrid with this structure: Column1 Column2 Column3 Name URL FilePathtoSaveTo There are 1000 rows in the grid and I want to use the url (Column2) in an httpwebrequest and httpwebresponse to get web pages and then use the FilePathtoSaveTo (Column3) to write the web page to disk. Anyone know of a foreach loop (or some other way) that will allow me to do this (return the cell values from columns 2 and 3 in order to be used as variables for my web request and write?) Thanks, Paul (Also, the urls return text files that when saved with the .html extension, open as html files.)
Well WHAT is your data source for the Grid? You need to iterate over your data source, NOT the data grid
-
I have a datagrid with this structure: Column1 Column2 Column3 Name URL FilePathtoSaveTo There are 1000 rows in the grid and I want to use the url (Column2) in an httpwebrequest and httpwebresponse to get web pages and then use the FilePathtoSaveTo (Column3) to write the web page to disk. Anyone know of a foreach loop (or some other way) that will allow me to do this (return the cell values from columns 2 and 3 in order to be used as variables for my web request and write?) Thanks, Paul (Also, the urls return text files that when saved with the .html extension, open as html files.)
bool keepGoing = true; for (int rowNum = 0; keepGoing; rowNum++) { try { /* Do Stuff with dataGrid[rowNum][2] and dataGrid[rowNum][3] */ } catch { keepGoing=false; } }
This will probably work, but I don't particularly like it...if you have a dataset with the information, you might want to iterate through that instead of the grid itself. - D -
Well WHAT is your data source for the Grid? You need to iterate over your data source, NOT the data grid
Sorry, it is a dataset. The main point is that I want to take a record then assign the value from that row, column2 to the variable that contains the url and then assign the value from that same row and column3 to the variable that will hold the pathname.filename to save as. I just haven't figured out exactly how to do it yet. (I've actually got to run now, but I'll be back later tonight) Thanks, Paul
-
bool keepGoing = true; for (int rowNum = 0; keepGoing; rowNum++) { try { /* Do Stuff with dataGrid[rowNum][2] and dataGrid[rowNum][3] */ } catch { keepGoing=false; } }
This will probably work, but I don't particularly like it...if you have a dataset with the information, you might want to iterate through that instead of the grid itself. - D -
So I simply designate the cell by iterating over the rows and then designating the column like this dataGrid[rowNum][2]? That simple? I'm using a dataset. Thanks, Paul (I've got to go now...be back later tonight.)
Actually, I messed the syntax up. You can get the value of a cell with: dataGrid[rowNum, colNum] I agree with the other post about using the dataset instead of the grid...but if you have to, you can use the grid. Keep in mind that if you use the datagrid instead of the dataset, you will have to find a way of counting the rows. This is why I used the try/catch block of stopping the loop in my example. I'm sure there are better ways...I'm just too lazy tonight to look anything up. Also, if you use the datagrid, you may have to check the values you get from the cells to make sure they are usable. If the grid is editable, you'll (almost) always have that extra row at the bottom that will have nothing, but you'll still be able to return the value from those cells. Good luck! - D
-
Sorry, it is a dataset. The main point is that I want to take a record then assign the value from that row, column2 to the variable that contains the url and then assign the value from that same row and column3 to the variable that will hold the pathname.filename to save as. I just haven't figured out exactly how to do it yet. (I've actually got to run now, but I'll be back later tonight) Thanks, Paul
Something like this:
DataTable table = theDataSet.Tables[0];
foreach(Row aRow in table.Rows)
{
string Url = aRow[1];
string SavePath = aRow[2];
}You can also use the name of the column instead of the ordinal position. Does this help?
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell The Second EuroCPian Event will be in Brussels on the 4th of September Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
-
Something like this:
DataTable table = theDataSet.Tables[0];
foreach(Row aRow in table.Rows)
{
string Url = aRow[1];
string SavePath = aRow[2];
}You can also use the name of the column instead of the ordinal position. Does this help?
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell The Second EuroCPian Event will be in Brussels on the 4th of September Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!