Skip to content

lucas-explica/DataGridViewExtensions

 
 

Repository files navigation

DataGridViewAssistant

A library of extensions for Windows forms data grid views.

This library is used for performing searches, updates, formatting and generic data binding for Windows Forms DataGridViews.

The following functions are included in the library. FindRows, UpdateCells, RemoveRows, FormatCells, BindData.

FindRows

FindRows takes a Func<DataGridViewCell, bool> parameter in order to find rows based on a specific data grid cells. Example:

var dataRowsSearched = _dataGridView.FindRows(x => x.Value.ToString() == "Grant");

UpdateCells

UpdateCells takes a Func<DataGridViewCell, bool> parameter for searching specific cells to update and a value for updating the searched cells. Example:

_dataGridView.UpdateCells(x => x.Value.ToString() == "[email protected]", "[email protected]");

RemoveRows

RemoveRows takes a Func<DataGridViewCell, bool> parameter for searching specific cells and removing the rows containing those cells. Example:

_dataGridView.RemoveRows(x => x.Value.ToString() == "[email protected]");

FormatCells

FormatCells takes a Func<DataGridViewCell, bool> parameter for searching specific cells and two additional parameters for formatting the cells font and background color. These parameters are System.Drawing.Color enums. Example:

_dataGridView.FormatCells(x => x.Value.ToString() == "[email protected]", Color.White, Color.Red);

BindData

BindData takes an IEnumerable<T> with T being any .Net class without nested collections and builds the data grid from that collection. The property names of the class become the column names. If there are description attributes on the properties, those will be used as the column header's. Example:

var contactInfo = new List<ContactInfoModel>
            {
                new ContactInfoModel
                {
                    Id = Guid.NewGuid(),
                    FirstName = "John",
                    LastName = "Doe",
                    Age = DateTime.Now.Year - new DateTime(1991, 9, 2).Year,
                    DateOfBirth = new DateTime(1991, 9, 2),
                    PhoneNumber = "(952) 564-1170",
                    Email = "[email protected]"
                },
                new ContactInfoModel
                {
                    Id = Guid.NewGuid(),
                    FirstName = "Jane",
                    LastName = "Doe",
                    Age = DateTime.Now.Year - new DateTime(1990, 8, 5).Year,
                    DateOfBirth = new DateTime(1990, 8, 5),
                    PhoneNumber = "(952) 564-2173",
                    Email = "[email protected]"
                }
            };

var dataGrid = new DataGridView();
dataGrid.BindData(contactInfo);

About

A library of extensions for Windows forms data grid views

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • C# 100.0%