SandGrid User Guide Populating and Viewing Data There are three ways in which you will populate a SandGrid control, but they all end up with either the GridRow class or a derived version. Manual To populate a SandGrid manually you simply instantiate GridRow classes, add cells to them and then add them to the Rows collection of your grid. The cell classes you use should correspond with the datatypes of the columns you use. In cases where you need to display hierarchical data, you simply add your row to the NestedRows collection of the parent row. DataBinding To bind the grid to data you set its DataSource property, and optionally DataMember too. SandGrid understands binding to the standard list types, e.g. IList, IBindingList and IBindingListView. When binding to a hierarchical data source like a DataSet the DataMember property directs the control to the initial table to display. SandGrid will detect when related views are available and will allow the user to expand them appropriately. When bound to data you cannot add or remove rows programmatically, as all rows must come from the data source. SandGrid will detect when the datasource changes and update its contents accordingly. Virtual Rows The architecture of SandGrid allows a simple GridRow-derived class to be written that bridges the gap between your business objects and the grid. You can therefore combine the simplicity of databinding with the flexibility that you gain from having individual row objects at your disposal for custom formatting. You can ensure that the display of your data is "live", i.e. the display comes straight from your data rather than a copy being placed in the control, which happens with manual population. The key methods in GridRow are GetCellValue and SetCellValue. The simplest form of virtual row is one that simply overrides GetCellValue and provides a value for the requested column. Typically your virtual rows represent business objects - they accept the object in their constructor and retain it, thereby allowing a simple switch statement in GetCellValue to return a value obtained from the object. The demonstration application included with SandGrid includes samples of virtual rows in the form of a Newsreader and Outlook style applications. Other methods that can be overridden to further customize the display of data include GetCellImage and DrawRowForeground. GetCellImage can dynamically return a different image depending on defined circumstances and in DrawRowForeground you can directly change the drawing process of the row, for instance adding details to it. Sorting SandGrid includes native sorting methods for manually populated data or virtual rows, and will use the sorting methods exposed by your data sources when databinding. These sort method are obviously quite different but are abstracted to one API. Standard sorting is where your rows are sorted by the data contained in one column, either ascending or descending. To apply standard sorting you use the SortColumn and SortDirection properties of the grid, regardless of your data source. SortDirection must always be either ascending or descending and SortColumn can either be a column in the grid or a null reference, to disable sorting. Multi-column sorting is also available and is exposed via the SetSort method of your grid. It accepts two corresponding arrays, one of the columns and one of their directions. Sorting is applied from the first column to the last. If you attempt to apply this type of sorting to a bound datasource that does not support it, it will fall back to simple sorting by the primary column. The current sort is indicated by the column(s) responsible, with a shaded background and a glyph in the header showing direction. Simple sorting can be set at design time. Grouping Grouping is an extension to sorting that logically groups rows by the values in the primary sort column. It does this by comparing values as the rows are laid out, and when the column determines that a significant change in value has occured a new group heading is created. The grouping itself is controlled by the column but is exposed via a simple boolean Group property on the grid. |