Hi,
I need to loop through a specific column(Not all the columns) in DataGridview amd update some values: For Example I have dataGridView populated with a csv file and contains 4 column as
Name, Age, Asset
Martin,32,350
John,19,12
Joay,47,1200
humberto,50,950
Richardo,62,23
I present the cells value in DataGridView on a WinForm now I would like to loop through the Columns just by the Column Name. For example How i I can loop through Column = Age and find all ages under 30 and How I can loop throuh the Asset column and add 100 to all values lesss than 500.
Please be advise that I need to serch the column by COULMN NAME because I am not getting the Csv file in the same order as mentioned abouve so i have to use a loop which find the coulmns by thir name
Thanks a lot
SenthilkumarPosted Apr 17, 2012, 2:40 AM
foreach(DataGridViewRow dgvr in dgvColumns.Rows)
//Assign the value to the column.
dr["Age"] = 100;
Krishna GaradPosted Apr 17, 2012, 2:41 AM
foreach (DataColumn cl in samples.Columns)
{
if (cl.ColumnName.ToString() != "Age")
{
var _values = from DataRow row in samples.Rows
select (string)row[cl.ColumnName.ToString()];
string[] _val = _values.ToArray();
}
}
Behrouz HosseiniPosted Apr 17, 2012, 2:22 AM
Thanks for your reply but can you please let me know how and which part of this code refers to any column name in datagridview? As I already mentioned I need to loop into a specific column (let say Age) and not into whole cells in datagridview
Once again Thanks for your comment
SenthilkumarPosted Apr 17, 2012, 2:15 AM
//Assign the value to the column.