/// ------------------------------------------------------------------------------------ public static GridSettings Create(DataGridView grid) { var gridSettings = new GridSettings(); var sortCol = grid.Columns.Cast<DataGridViewColumn>() .FirstOrDefault(c => c.HeaderCell.SortGlyphDirection != SortOrder.None); if (sortCol != null) { gridSettings.SortedColumn = sortCol.Name; gridSettings.SortDirection = sortCol.HeaderCell.SortGlyphDirection.ToString(); } gridSettings.ColumnHeaderHeight = grid.ColumnHeadersHeight; gridSettings.Columns = (from c in grid.Columns.Cast<DataGridViewColumn>() select new GridColumnSettings { Id = c.Name, Width = c.Width, FillWeight = c.FillWeight, Visible = c.Visible, DisplayIndex = c.DisplayIndex }).ToArray(); return gridSettings; }