-
-
Notifications
You must be signed in to change notification settings - Fork 342
GridView
rooly4 edited this page Jun 5, 2014
·
5 revisions
GridViews require an indexed DataStore and a list of Columns with associated Cell handlers.
There are a number of available Cell handlers:
- CheckBoxCell
- ComboBoxCell
- ImageTextCell
- ImageViewCell
- TextBoxCell
When creating these, you should associate the Column they will be referencing either via index or property name.
The DataStore can be filled by constructing a DataStoreCollection. You should provide an enumerable of indexed arrays.
var collection = new DataStoreCollection( new List<string[]>() { {"a","b","c"}, {"d","e","f"} } );
To load data into a GridView from a System.Data.DataTable (as commonly provided by SQL sources),
var collection = new DataStoreCollection (dt.Rows.Cast<DataRow> ()
.Select (x => x.ItemArray.Select (y => y.ToString ()).ToArray()));
var grid = new GridView () {
DataStore = collection,
ShowCellBorders = true
};
int i = 0;
foreach (var col in dt.Columns.Cast<DataColumn>()) {
grid.Columns.Add (new GridColumn () {
DataCell = new TextBoxCell (i++),
HeaderText = col.ColumnName
});
}