WinUI コントロール
非バインド モード
コントロール > FlexGrid > データ > 非バインド モード

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.

private void Grid_Loaded(object sender, RoutedEventArgs e)
  {
      // マージを許可します。
      flexGrid1.AllowMerging = GridAllowMerging.All;
      flexGrid1.HorizontalAlignment = HorizontalAlignment.Center;
      flexGrid1.VerticalAlignment = VerticalAlignment.Center;
      flexGrid1.GridLinesVisibility = GridLinesVisibility.All;
      flexGrid1.AllowResizing = GridAllowResizing.Both;
    // バインドされていない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());
      }
    // バインドされていないFlexGridにインデックスなどの値を入力します
      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);
         }
      }
  }
<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.