Skip to content

DevExpress-Examples/winforms-grid-custom-columns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WinForms Data Grid - Create custom columns

This example demonstrates how to create a custom grid column.

Create a GridColumn descendant class. If you add properties to a custom column and want to serialize them (using the SaveLayoutTo... method), apply the XtraSerializableProperty attribute.

public class MyGridColumn : GridColumn {
    public MyGridColumn() { }
    string customDataValue = string.Empty;

    [XtraSerializableProperty()]
    public string CustomData {
        get { return customDataValue; }
        set { customDataValue = value; }
    }
    protected override void Assign(GridColumn column) {
        base.Assign(column);
        if(column is MyGridColumn) {
            this.CustomData = ((MyGridColumn)column).CustomData;
        }
    }
}

Create a descendant from the GridColumnCollection class and override the CreateColumn method to instantiate a custom column:

public class MyGridColumnCollection : GridColumnCollection {
    public MyGridColumnCollection(ColumnView view) : base(view) { }
    protected override GridColumn CreateColumn() {
        return new MyGridColumn();
    }
}

Create a descendant from the GridView class and override the CreateColumnCollection method to instantiate your column collection:

public class MyGridView : DevExpress.XtraGrid.Views.Grid.GridView {
  public MyGridView() : this(null) {}
  public MyGridView(DevExpress.XtraGrid.GridControl grid) : base(grid) {
    // Your initialization code.
  }
  protected override string ViewName { get { return "MyGridView"; } }
  protected override GridColumnCollection CreateColumnCollection() {
    return new MyGridColumnCollection(this);
  }
}

Files to Review

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Contributors 2

  •  
  •  

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy