c# - How to select max and min value of any column of datagridview -
i have datagridview control on windows form. need select max , min value of column. in data-table can using this
code
int maxid = curriculmdatatable.asenumerable().max(r => r.field<int>("id"));
how can achieve in datagridview.
you can try:
var maxid = datagridview1.rows.cast<datagridviewrow>() .max(r => convert.toint32(r.cells["id"].value));
make sure id
cell has int
type value, otherwise use int.tryparse
like:
int temp; var maxid2 = datagridview1.rows.cast<datagridviewrow>() .max(r => int.tryparse(r.cells["id"].value.tostring(), out temp) ? temp : 0 );
Comments
Post a Comment