CoreSuite.Extensions.Windows
1.0.0
dotnet add package CoreSuite.Extensions.Windows --version 1.0.0
NuGet\Install-Package CoreSuite.Extensions.Windows -Version 1.0.0
<PackageReference Include="CoreSuite.Extensions.Windows" Version="1.0.0" />
<PackageVersion Include="CoreSuite.Extensions.Windows" Version="1.0.0" />
<PackageReference Include="CoreSuite.Extensions.Windows" />
paket add CoreSuite.Extensions.Windows --version 1.0.0
#r "nuget: CoreSuite.Extensions.Windows, 1.0.0"
#:package CoreSuite.Extensions.Windows@1.0.0
#addin nuget:?package=CoreSuite.Extensions.Windows&version=1.0.0
#tool nuget:?package=CoreSuite.Extensions.Windows&version=1.0.0
CoreSuite.Extensions.Windows
Windows Forms extensions for converting collections to tables and populating DataGridView controls.
CoreSuite.Extensions.Windows is one of the libraries included in the CoreSuite solution. It contains the Windows-specific extensions and depends on CoreSuite.Helpers.
Overview
CoreSuite.Extensions.Windows converts object and dictionary collections to DataTable instances and provides a convenient method for filling a Windows Forms DataGridView. Object conversion supports property exclusion through IgnoreInToTableAttribute, while grid population can preserve the selected row, scroll position and sort direction and can optionally display an order column.
This package is intended for .NET 8 Windows Forms applications. General-purpose string utilities remain in the separate CoreSuite.Extensions package.
Features
- Converts object collections to
DataTableinstances through public properties. - Converts dictionary collections to tables using dictionary keys as columns.
- Excludes selected model properties through
IgnoreInToTableAttribute. - Represents
Lazy(Of T)properties without evaluating their values. - Populates an existing
DataGridViewfrom any supported collection. - Optionally preserves the selected row and first displayed row.
- Optionally reapplies the current grid sort.
- Optionally inserts a one-based
Ordercolumn as the first column. - Includes English XML documentation for the public API.
- Requires no third-party packages.
Requirements
- .NET 8 for Windows (
net8.0-windows) - Windows Forms
CoreSuite.Helpers
The NuGet dependency on CoreSuite.Helpers is resolved automatically when the package is installed.
Installation
Install the package from NuGet:
dotnet add package CoreSuite.Extensions.Windows
Or use the Visual Studio NuGet Package Manager and search for:
CoreSuite.Extensions.Windows
Namespaces
The extension methods and the exclusion attribute use these namespaces:
Imports CoreSuite.Extensions
Imports CoreSuite.Extensions.Extensions
Quick start
Imports System.Data
Imports CoreSuite.Extensions.Extensions
Dim Customers As New List(Of Customer) From {
New Customer With {.Id = 1, .Name = "Ana"},
New Customer With {.Id = 2, .Name = "Bruno"}
}
Dim CustomerTable As DataTable = Customers.ToTable()
DataGridView1.Fill(Customers)
API reference
Collection extensions
| Member | Behavior |
|---|---|
ToTable(source As IEnumerable) |
Converts the public properties of each collection item to columns and rows. |
ToTable(source As IEnumerable(Of Dictionary(Of String, Object))) |
Creates columns from all discovered dictionary keys and rows from their values. |
DataGridView extension
| Member | Default | Behavior |
|---|---|---|
Fill(dgv, collection, keepSelection, keepSort, showOrder) |
True, True, True |
Converts the collection to a table, assigns it to DataSource and restores the requested grid state. |
Attribute
| Type | Behavior |
|---|---|
IgnoreInToTableAttribute |
Excludes a public property from object-to-table conversion. |
Convert an object collection to a DataTable
Each public property of the collection item type becomes a DataColumn, and each item becomes a DataRow.
Imports System.Data
Imports CoreSuite.Extensions.Extensions
Dim Products As New List(Of Product) From {
New Product With {.Id = 1, .Name = "Keyboard", .Price = 120D},
New Product With {.Id = 2, .Name = "Mouse", .Price = 80D}
}
Dim ProductTable As DataTable = Products.ToTable()
Properties of type Lazy(Of T) are represented by text in the form Lazy<TypeName> and are not evaluated.
Ignore a property
Apply IgnoreInToTableAttribute to a model property that must not become a table column:
Imports CoreSuite.Extensions
Public Class Customer
Public Property Id As Integer
Public Property Name As String
<IgnoreInToTable>
Public Property InternalNotes As String
End Class
The attribute is useful for calculated values, complex objects, internal references or any other property that should not appear in the resulting DataTable.
Convert dictionaries to a DataTable
Every distinct key found across the dictionaries becomes a column. A missing or Nothing value is stored as DBNull.Value.
Imports System.Data
Imports CoreSuite.Extensions.Extensions
Dim Rows As New List(Of Dictionary(Of String, Object)) From {
New Dictionary(Of String, Object) From {{"Id", 1}, {"Name", "Ana"}},
New Dictionary(Of String, Object) From {{"Id", 2}, {"Name", "Bruno"}, {"Active", True}}
}
Dim Table As DataTable = Rows.ToTable()
Column names are collected case-insensitively. The dictionary collection overload returns Nothing when its source is Nothing.
Fill a DataGridView
Imports CoreSuite.Extensions.Extensions
DataGridView1.Fill(
Products,
KeepSelection:=True,
KeepSort:=True,
ShowOrder:=True)
Parameters
| Parameter | Default | Description |
|---|---|---|
Collection |
Required | Collection converted through ToTable. |
KeepSelection |
True |
Preserves the selected row index and first displayed row when exactly one row is selected. |
KeepSort |
True |
Reapplies the current sort column and direction after rebinding. |
ShowOrder |
True |
Adds a one-based Order column and places it at index zero. |
Fill replaces the grid's current DataSource with the generated DataTable.
Important behavior
- Object conversion reads public properties through reflection, so ordinary property getters are executed.
- A string is not treated as a collection of items and causes
InvalidOperationExceptionin the object collection overload. - The non-generic object collection must not be
Nothing. - A model property named
Orderconflicts with the optional order column. SetShowOrder:=Falsewhen the source already contains that column name. - Selection is preserved only when the grid has exactly one selected row before it is filled.
- Grid sorting depends on the generated columns supporting the previous sort operation.
IgnoreInToTableAttributeaffects object conversion only; dictionary keys are not filtered by the attribute.
Package information
| Item | Value |
|---|---|
| Package | CoreSuite.Extensions.Windows |
| Namespaces | CoreSuite.Extensions, CoreSuite.Extensions.Extensions |
| Assembly | CoreSuite.Extensions.Windows |
| Target framework | net8.0-windows |
| UI framework | Windows Forms |
| CoreSuite dependency | CoreSuite.Helpers |
| External dependencies | None |
License
This package is distributed under the MIT License defined by the CoreSuite repository.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0-windows7.0 is compatible. net9.0-windows was computed. net10.0-windows was computed. |
-
net8.0-windows7.0
- CoreSuite.Helpers (>= 1.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 99 | 8/3/2026 |
Initial release of collection-to-DataTable and DataGridView extensions for Windows Forms.