# Defining Columns

## Content



With automatic column generation as one of the default features of FlexGrid, the control lets you specify the columns, allowing you to choose which columns to show, and in what order. This gives you control over each column's width, heading, formatting, alignment, and other properties. To define columns for the FlexGrid, ensure that the [AutoGenerateColumns](/componentone/api/xamarin/online-forms/dotnet-api/C1.Xamarin.Forms.Grid/C1.Xamarin.Forms.Grid.FlexGrid.AutoGenerateColumns.html) is set to **false** (by default this property is **true**).

The image below shows how the FlexGrid appears, after defining columns.

![FlexGrid Defining Columns](https://cdn.mescius.io/document-site-files/images/fb6b46a2-eac0-487c-84c3-5e1b4c7b1348/images/flexgriddefiningcolumns.png)

The following code example demonstrates how to define FlexGrid columns in C# and XAML. The example uses the sample created in the [Quick start](/componentone/docs/xamarin/online-forms/controls/OverviewFlexGrid/flexGridQuickStart) section.

1.  Add the following code to the MainPage.xaml page for defining columns in the FlexGrid.
    
    ```xml
    <Grid VerticalOptions="FillAndExpand">
       <c1:FlexGrid x:Name="grid" AutoGenerateColumns="False">
          <c1:FlexGrid.Columns>
            <c1:GridColumn Binding="ID" Width="100"/>
            <c1:GridColumn Binding="First" Width="Auto"/>
            <c1:GridColumn Binding="Last"/>
            <c1:GridColumn Binding="OrderTotal" Format="N2"/>
          </c1:FlexGrid.Columns>
        </c1:FlexGrid>
    </Grid>
    ```
    
    <br />
2.  Open MainPage.xaml.cs and add the following code to display data in the FlexGrid control.
    
    ```csharp
    var data = Customer.GetCustomerList(100);
    grid.ItemsSource = data;
    ```