0

I have a (Devexpress) Datagrid-Control, which contains 3 columns of information. The names of the columns are generated automatically, each line describes one object of those:

    private string fName;
    private bool fCheck;
    private DateTime fDate;
    public bool checked
    {
        get { return this.fCheck; }
        set { this.fCheck = value; }
    }
    public string fileName
    {
        get { return this.fName; }
        set { this.fName = value; }
    }

    public DateTime createDate
    {
        get { return this.fDate; }
        set { this.fDate = value; }
    }

These Objects are saved in a List<> (dataSource):

gridFiles.DataSource = dataSource;
gridFiles.MainView.PopulateColumns();

Now, the names of the Columns are "checked","fileName" & "createDate". How can I change those?

Marcel
  • 917
  • 3
  • 19
  • 48
  • possible duplicate of [Change devexpress grid control column header caption](http://stackoverflow.com/questions/3751516/change-devexpress-grid-control-column-header-caption) – nempoBu4 Feb 04 '15 at 07:03
  • that doesn'T work for me. I don't have a "columns"-property on my gridview – Marcel Feb 04 '15 at 07:06
  • What type of `GridView` are you using? – nempoBu4 Feb 04 '15 at 07:14
  • If you can't use your `gridView` object directly, then you can use `gridFiles.MainView` property and convert it to `ColumnView`: `var columns = ((ColumnView)gridFiles.MainView).Columns;` – nempoBu4 Feb 04 '15 at 07:19

2 Answers2

3

Veeramani's answer does the job perfectly but just thought I should share an alternative solution with take less coding. You can also achieve this by adding a DisplayName attribute on each property. i.e:

My Class:

public class GridColumns
{
    private string fName;
    private bool fCheck;
    private DateTime fDate;

    [DisplayName("Checked Option")]
    public bool Checked
    {
        get { return fCheck; }
        set { this.fCheck = value; }
    }

    [DisplayName("File Name")]
    public string fileName
    {
        get { return this.fName; }
        set { this.fName = value; }
    }

    [DisplayName("Date Created")]
    public DateTime createDate
    {
        get { return this.fDate; }
        set { this.fDate = value; }
    }

}

Then use it:

List<GridColumns> dataSourc = new List<GridColumns>();
dataGridView1.DataSource = dataSourc;
Bayeni
  • 1,046
  • 9
  • 16
0

Using Gridview, we can rename the column name at Form_load() event...

gridView1.Columns["fileName"].Caption = "Your custom name";
Veeramani Bala
  • 234
  • 3
  • 12