public static IGridColumn FromNativeColumn(AccessibleColumnHeader nativeColumn)
            {
                var gridColumn = new GridColumn
                {
                    Name    = nativeColumn.Name,
                    Caption = nativeColumn.Text,
                    Visible = nativeColumn.Visible,
                };

                return(gridColumn);
            }
            public static AccessibleColumnHeader ToNativeColumn(IGridColumn gridColumn)
            {
                var ourGridColumn = (GridColumn)gridColumn;
                var nativeColumn  = new AccessibleColumnHeader
                {
                    Name    = ourGridColumn.Name,
                    Text    = ourGridColumn.Caption,
                    Visible = ourGridColumn.Visible,
                };

                return(nativeColumn);
            }
 private void DataBind()
 {
     using (new BeforeAfter(BeginUpdate, EndUpdate))
     {
         this.Items.Clear();
         if (_dataSource != null)
         {
             // TODO: We might be better off never creating the hidden columns' headers in the first place
             var columns        = _dataSource.Columns.Count;
             var visibleColumns = Columns.Cast <AccessibleColumnHeader>().Where(c => c.Visible).ToList();
             if (Columns.Count != visibleColumns.Count)
             {
                 Columns.Clear();
                 foreach (var accessibleColumnHeader in visibleColumns)
                 {
                     Columns.Add(accessibleColumnHeader);
                 }
             }
             var lastColumn = (AccessibleColumnHeader)Columns[Columns.Count - 1];
             if (lastColumn.Text != String.Empty)
             {
                 // dummy column for the auto-sizing
                 var header = new AccessibleColumnHeader {
                     Text = String.Empty
                 };
                 Columns.Add(header);
                 visibleColumns.Add(header);
             }
             var dataRows              = _dataSource.AsEnumerable();
             var sourceColumn          = MapToSourceColumn(_dataSource.Columns.Cast <DataColumn>(), _sortingColumn);
             var potentiallySortedRows = dataRows;
             if (_sortingColumn != -1)
             {
                 if (_sortOrder == SortOrder.Ascending)
                 {
                     potentiallySortedRows = dataRows.OrderBy(r => r[sourceColumn], TheColumnComparer);
                 }
                 else
                 {
                     potentiallySortedRows = dataRows.OrderByDescending(r => r[sourceColumn], TheColumnComparer);
                 }
             }
             var row = 0;
             foreach (var dataRow in potentiallySortedRows)
             {
                 var strings = new List <string>(columns);
                 for (var c = 0; c < columns; c++)
                 {
                     if (_dataSource.Columns[c].IsVisible())
                     {
                         var value = dataRow.ItemArray[c];
                         strings.Add(value == null ? String.Empty : value.ToString());
                     }
                 }
                 var listViewItem = new ListViewItem(strings.ToArray())
                 {
                     BackColor = (row % 2 == 0) ? this.BackColor : AlternatingBackColor,
                     Tag       = dataRow,
                 };
                 row++;
                 this.Items.Add(listViewItem);
             }
         }
     }
 }