9
Here’s the thing, I got a DataGridView with several columns. In each row of this DataGridView a program installation path will be shown. With this value displayed, I would like to use it to get the size of that folder and put it in a new column.
I have a method to calculate the size of a string:
private static long ObterTamanhoDiretorio(string tamanhoDir)
{
DirectoryInfo dire = new DirectoryInfo(tamanhoDir.ToString());
return dire.EnumerateFiles("*.*", SearchOption.AllDirectories).Sum(fi => fi.Length);
}
I don’t know if it’s something like this I have to use.
foreach (DataGridViewRow item in dataGridView1.Rows)
{
}
What I’d like to know is how to get that value by seeing on each line. If you have any ideas, thank you.
If you already have the paths on
DataSourcebefore setting inDataGridView, you can make aforeachdirectly into your data source, which should be aListor aDataTable. You can also use the eventRowDataBoundofDataGridView, which will read each row being rendered on the grid, so you can take the value of the column and move to its method to calculate the size.– Ricardo Pontual
How you fill the Datagridview?
– Rovann Linhalis