How to Select maximum value in datatable?
How to select maximum vaue in datatable?
Collapse
X
-
Tags: None
-
Using a Google search I found some code at http://www.devx.com/codemag/Article/35186/1763/page/4 and modified it.
Add this code to your function.
It will search a specified column to find its max value and select its cell.
Hope this helps.Code://Call using 'FindMaxValue(DataGridView1, 0);' public long MaxValue; public void FindMaxValue(DataGridView dgv, int colIndex) { MaxValue = 0; for (int rowIndex = 0; rowIndex < dgv.Rows.Count; rowIndex++) { DataGridViewRow row = dgv.Rows[rowIndex]; if (MaxValue != Math.Max(MaxValue, Convert.ToInt64(row.Cells[colIndex].Value))) { dgv.row.Cells[colIndex].Selected = true; MaxValue = Convert.ToInt64(row.Cells[colIndex].Value); } } }
Sam -
You can use Select Method of DataTable class.
Have a look at this http://msdn.microsoft.com/en-us/library/way3dy9w.aspxComment
Comment