Quick Start

This quick start guides you through the steps of creating a simple List application. You begin by creating a Windows Forms App in Visual Studio, adding he List control to the Form and binding it to a data source.

Follow the given steps to create a simple List application in .NET Edition.

Displays List control

Set Up the Application

  1. Create a new Windows Forms App and set the project framework to .NET 6.0 using Configure your new project window.
  2. Install C1.Win.List package using NuGet Package Manager. The C1List control gets added to the Toolbox once the package gets installed.
  3. Drag and drop the List control from Toolbox onto the Form.

Bind List to a Data Source

  1. Create a class named Product to be used as a data source.
    C#
    Copy Code
    public class Product
    {
        // Create a custom class Product
       
            static Random _rnd = new Random();
            static string[] _names = "Macko|Surfair|Pocohey|Studeby".Split('|');
            static string[] _lines = "Computers|Washers|Stoves|Cars".Split('|');
            static string[] _colors = "Red|Green|Blue|White".Split('|');
            public Product()
            {
                Name = _names[_rnd.Next() % _names.Length];
                Line = _lines[_rnd.Next() % _lines.Length];
                Color = _colors[_rnd.Next() % _colors.Length];
                Price = 30 + _rnd.NextDouble() * 1000;
                Cost = 3 + _rnd.NextDouble() * 300;
                Discontinued = _rnd.NextDouble() < .2;
                Introduced = DateTime.Today.AddDays(_rnd.Next(-600, 0));
            }
            public string Name { get; set; }
            public string Color { get; set; }
            public string Line { get; set; }
            public double Price { get; set; }
            public double Cost { get; set; }
            public DateTime Introduced { get; set; }
            public bool Discontinued { get; set; }
        }
    

  2. Initialize a list of type Product.
    C#
    Copy Code
    // Initialises a List of type Product, where Product is a class type
    List<Product> _products = new List<Product>();
    

  3. Initialize a for loop to add products using the Add method as shown in the following code.
    C#
    Copy Code
    // Initialize for loop and add products to the list
    for (int i = 0; i < 10; i++)
    {
        _products.Add(new Product());
    }
    

  4. Bind the List control to a data source by using DataSource property of the C1List class.
    C#
    Copy Code
    // Bind list with data           
    c1List1.DataSource = _products;
    

Configure the List control

Add the following code to initialize and add the List control to the Form at runtime.

C#
Copy Code
// Initialize the control
C1List c1list1 = new C1List();
// Add the control to form
this.Controls.Add(c1list1);