Now, I have a member UltraGridRow row. I want to get the column collection by the row and find the max value of the specific column. how can i do ?
Hello Steve,
Right now UltraGrid does not expose a property or method allowing you to automatically find the max value of a particular column. To do so you should either iterate all the rows in the band you are looking for max value like this:
UltraGridBand band = column.Band;foreach(UltraGridRow r in band.GetRowEnumerator(GridRowType.DataRow)){ var cellValue = r.GetCellValue(col); // TODO: Get the max one}
or use lambda expression like this one:
UltraGridBand band = column.Band;var maxValue = band .GetRowEnumerator(GridRowType.DataRow) .OfType<UltraGridRow>() .Max(r => r.GetCellValue(column));
Please let me know if any additional questions on this matter arise.
thank you for you reply, is there a function that can automatically find the max value of a column in ultragrid?
To get the columns of the band where the row is you can use code like this:ColumnsCollection columns = row.Band.Columns;
Regarding the max value it is depending on from which values you need the max one. You may iterate all the columns in particular row like this:
foreach(UltraGridCell cell in row.Cells){ var cellValue = cell.Value; // TODO: Get the max one}
or you may iterate the rows in particular column like this:
UltraGridBand band = row.Band;foreach(UltraGridRow r in band.GetRowEnumerator(GridRowType.DataRow)){ var cellValue = r.GetCellValue(col); // TODO: Get the max one}
or you can combine both these and iterate entire band. For additional information about how to loop through entire grid you may check this article in our online documentation “Looping Through the Entire Grid”.