Grid / Columns / Data Columns
In This Topic
    Data Columns
    In This Topic
     About Data Columns

    Data columns are columns that are designed to be bound to a specific data source field. Data columns are represented by the NDataColumn class. Usually data columns are created automatically when you bind the grid to data (see Data Binding and Column Generation). You can however manually create data columns like this:

    Data Columns
    Copy Code
    // create a dummy data table
    NMemoryDataTable dataTable = new NMemoryDataTable(new NFieldInfo[]{
        new NFieldInfo("Name", typeof(String)),
        new NFieldInfo("Job Title", typeof(String)),
    });
    dataTable.AddRow("Jinny Collazo", "President");
    dataTable.AddRow("John Duke", "VicePresident");
    dataTable.AddRow("Kellie Ferrell", "SalesManager");
    // bind the grid to the data source, but do not auto create columns
    grid.AutoCreateColumns = false;
    grid.DataSource = new NDataSource(dataTable);
    // create a data column and bind it to the data source
    NDataColumn dataColumn = new NDataColumn();
    dataColumn.Bind(grid.DataSource, "Job Title", "Job Title");
    grid.Columns.Add(dataColumn);
    

    As you can see the binding of a data column to a data source field is achieved via the data column Bind method.

     Field Information

    Several properties of each data column expose useful information about the column. Following is a brief overview:

    Property Description
    FieldName Gets the name of the data source field, to which the data column is bound to.
    FieldIndex Gets the index of the data source field,  to which the data column is bound to.
    FieldType Gets the type of the data source field, to which the data column is bound to.
    FieldNullable Gets whether the data source field accepts null values.

     Querying for Data Columns

    You can get the first data column that is bound to a specific data source field by using the following code:

    Getting the first data column that is bound to a field
    Copy Code
    NDataColumn dataColumn = grid.Columns.GetColumnByFieldName("Job Title");
    

    There can be multiple data columns that are simultaneously bound to the same data source field. You can get all these columns by using the following code:

    Getting all data columns that are bound to a field
    Copy Code
    NDataColumn[] dataColumns = grid.Columns.GetAllColumnsByFieldName("Job Title");