Displays data in tabular form with one or several headers

Namespace: Dapfor.Wpf.Controls
Assembly: Dapfor.Wpf (in Dapfor.Wpf.dll) Version: 4.1.0.26317 (4.1.0.26317)

Syntax

C#
public class GridControl : Control
Visual Basic
Public Class GridControl
	Inherits Control
Visual C++
public ref class GridControl : public Control
F#
type GridControl =  
    class
        inherit Control
    end

Remarks

Besides, connection to IList, IBindingList, IListSource, Dapfor Wpf GridControl significantly expands data binding features enabling operations in unbound mode.

As an example of usage we shall demonstrate a simple class and a collection of objects of this class that can be later displayed in the grid.

 Copy imageCopy
//An example of a simple class 
public class MyCustomClass
{
    public MyCustomClass(int intValue, double doubleValue, string stringValue)
    {
        IntValue = intValue;
        DoubleValue = doubleValue;
        StringValue = stringValue;
    }

    public int IntValue { get; set; }
    public double DoubleValue { get; set; }
    public string StringValue { get; set; }
}

//Collection with some MyCustomClass objects 
public class MyCollection : List<MyCustomClass>
{
    public MyCollection()
    {
        //Add some data 
        Add(new MyCustomClass(10, 11.12, "some string 1"));
        Add(new MyCustomClass(20, 21.33, "some string 2"));
    }
}

There are many methods of binding grid to data. Let's demonstrate an xaml file as the simplest example of this. To do it, we shall add GridControl from toolbox to VisualStudio and create a header and some columns. Data is created in DataTypesWindow resources and bound to the grid as a static resource: ItemsSource="{StaticResource myCollection}"

 Copy imageCopy
<Window x:Class="TestApplication.Tutorial.DataTypesWindow" 
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:df="clr-namespace:Dapfor.Wpf.Controls;assembly=Dapfor.Wpf" 
           xmlns:Tutorial="clr-namespace:TestApplication.Tutorial"
           Title="Objects of arbitrary classes" Height="352" Width="671"> 

  <Window.Resources> 
    <Tutorial:MyCollection x:Key="myCollection"/> 
  </Window.Resources> 

  <df:GridControl Name="grid" ItemsSource="{StaticResource myCollection}"> 
    <df:GridControl.Headers> 
      <df:Header ScrollType="Stretch"> 
        <df:Header.Columns> 
          <df:Column Id="IntValue" Title="Int Value" /> 
          <df:Column Id="DoubleValue" Title="Double Value" /> 
          <df:Column Id="StringValue" Title="String Value" /> 
        </df:Header.Columns> 
      </df:Header> 
    </df:GridControl.Headers> 
  </df:GridControl> 
</Window>

Besides the above example, the grid can also be bound to data with programming means. For example, in DataTypesWindow class designer.

 Copy imageCopy
// Interaction logic for DataTypesWindow.xaml 
public partial class DataTypesWindow : Window
{
    public DataTypesWindow()
    {
        InitializeComponent();

        //Bind the Wpf GridControl to the collection MyCollection using program means 
        IList<MyCustomClass> collection = new List<MyCustomClass>
        collection.Add(new MyCustomClass(10, 11.12, "some string 1"));
        collection.Add(new MyCustomClass(20, 21.33, "some string 2"));

        grid.ItemsSource = collection;
    }
}

GridControl provides access to rows via GridControl.Rows or GridControl.Nodes accessors for any method that has been used to fill the grid. The grid returns objects of Row type. Developers can use Wpf GridControl to easily create a hierarchy by calling Row.Add(object) method.

 Copy imageCopy
Row row = grid.Rows[1];
row.Add(new object[] { 200, null,"subitem1"});
row.Add(new object[] { 33, 33.33,"subitem2" });

Inheritance Hierarchy

See Also