WinUI | ComponentOne
Controls / FlexGrid / Data / Unbound Mode
In This Topic
    Unbound Mode
    In This Topic

    The FlexGrid control is designed to work with various data sources and collections such as ObservableCollection and DataCollection to leverage its full capabilities. However, the control is not restricted to data sources and can be used in unbound mode.

    The image given below shows an unbound grid populated with cell index notation.

    To create an unbound grid, add rows and columns to the grid using the Add method. The following code illustrates adding rows and columns in a grid and populating it with an indexing notation that specifies a cell by corresponding row and column index by calling the Grid_Loaded event.

    C#
    Copy Code
    private void Grid_Loaded(object sender, RoutedEventArgs e)
     {
         // allow merging
         flexGrid1.AllowMerging = GridAllowMerging.All;
         flexGrid1.HorizontalAlignment = HorizontalAlignment.Center;
         flexGrid1.VerticalAlignment = VerticalAlignment.Center;
         flexGrid1.GridLinesVisibility = GridLinesVisibility.All;
         flexGrid1.AllowResizing = GridAllowResizing.Both;
        // add rows/columns to the unbound flexGrid
         for (int i = 0; i < 10; i++)
         {
            flexGrid1.Columns.Add(new GridColumn());
         }
         for (int i = 0; i < 20; i++)
         {
            flexGrid1.Rows.Add(new GridRow());
         }
        // populate the unbound flexGrid with some value like indexes
         for (int r = 0; r < flexGrid1.Rows.Count; r++)
         {
            for (int c = 0; c < flexGrid1.Columns.Count; c++)
            {
              flexGrid1[r, c] = string.Format("[{0},{1}]", r, c);
            }
         } 
     }
    

    In the XAML code, set the HeadersVisibility property to All.

    XAML
    Copy Code
    <Grid Loaded="Grid_Loaded">
        <c1:FlexGrid Name="flexGrid1" HeadersVisibility="All" ></c1:FlexGrid>
     </Grid>
    

    As you can observe from the code snippet, here we have set the GridAllowMerging and GridLinesVisibility enumeration to All, so that all areas can be merged and we can see all horizontal and vertical grid lines. Further, we have also wrapped the header text using WordWrap property. 

    The indexing notation displayed in the grid specifies a cell by row and column index. The cells can also be specified by row index and column name, or by row index and column name. The indexing notation works in bound and unbound modes. In bound mode, the data is retrieved or applied to the items in the data source. In unbound mode, the data is stored internally by the grid.