In that case:
int sortColumn = 0;
if(dataGrid.ColumnCount > sortColumn)
{
dataGrid.Sort(dataGrid.Columns[sortColumn], System.ComponentModel.ListSortDirection.Ascending);
int minValue = -1;
int minValueRow = -1;
int maxValue = -1;
int maxValueRow = -1;
int.TryParse(dataGrid.Rows[0].Cells[sortColumn].Value.ToString(), out minValue);
minValueRow = dataGrid.Rows[0].Index;
int.TryParse(dataGrid.Rows[(dataGrid.Rows.Count - 1)].Cells[sortColumn].Value.ToString(), out maxValue);
maxValueRow = dataGrid.Rows[(dataGrid.Rows.Count - 1)].Index;
}
Sort Column should be the columnNumber you want to sort and now the min and max values from.
A better way without sorting at all is:
int cell = 0;
if (dataGrid.Rows.Count > 0)
{
int minValue = Convert.ToInt32(dataGrid.Rows[0].Cells[cell].Value);
int minValueRow = 0;
int maxValue = Convert.ToInt32(dataGrid.Rows[0].Cells[cell].Value);
int maxValueRow = 0;
for (int i = 0; i < dataGrid.Rows.Count; i++)
{
int num = Convert.ToInt32(dataGrid.Rows[i].Cells[cell].Value);
if (minValue > num)
{
minValue = num;
minValueRow = i;
}
if (maxValue < num)
{
maxValue = num;
maxValueRow = i;
}
}
}