Bunifu Datagrid View
Optimized theme design for high-performance; Flexible data editing, multiple data binding methods, and data export.

Overview

Bunifu Datagrid View is a feature-rich .NET valuable control for displaying data in a tabular format. It comes with beautiful in-built themes and a vast range of functions: data binding, editing, adding, custom sorting, selecting, and support for PDF formats.
Could not load image

Getting Started

This section provides a quick overview of working with the tabular data for WinForms. We shall walk through the entire process of creating a real-world data grid.

Adding BunifuDatagridView at Design Time

It's easy to add BunifuDatagridView control at design time. Start by locating BunifuDatagridView from your toolbox and drag it to your form as shown below. Then customize it to your desired look and feel using properties elaborated on later in this documentation.

Adding BunifuDataGridView at Run Time

BunifuDataGridView works for both C# and VB.NET. We will use the Form’s Load event to write our sample code to create a BunifuDatagridView and populate the table with built-in sample data.
C#
VB.NET
1
using System;
2
using Bunifu.UI.WinForms;
3
using System.Drawing;
4
using System.Windows.Forms;
5
6
namespace BunifuGrid
7
{
8
public partial class Form1 : Form
9
{
10
public Form1()
11
{
12
InitializeComponent();
13
}
14
15
private void Form1_Load(object sender, EventArgs e)
16
{
17
BunifuDataGridView bunifuDataGridView = new BunifuDataGridView();
18
bunifuDataGridView.Size = new Size(600, 250);
19
bunifuDataGridView.Location = new Point(12, 28);
20
this.Controls.Add(bunifuDataGridView);
21
bunifuDataGridView.PopulateWithSampleData();
22
}
23
}
24
}
25
Copied!
1
Imports System
2
Imports Bunifu.UI.WinForms
3
Imports System.Drawing
4
Imports System.Windows.Forms
5
6
Namespace BunifuGrid
7
Partial Public Class Form1
8
Inherits Form
9
10
Public Sub New()
11
InitializeComponent()
12
End Sub
13
14
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
15
Dim bunifuDataGridView As New BunifuDataGridView()
16
bunifuDataGridView.Size = New Size(600, 250)
17
bunifuDataGridView.Location = New Point(12, 28)
18
Me.Controls.Add(bunifuDataGridView)
19
bunifuDataGridView.PopulateWithSampleData()
20
End Sub
21
End Class
22
End Namespace
23
Copied!
Here's the output for the above code:

Creating a simple data entry application (No code!)

Step 1: Create the following form below with the following controls as shown on the labels.
For the DataGridView set the backgroundColor property to a color value of white.
Step two: Create columns on the Datagrid. Here's how to do it in the design view:
a) Select the Datagrid and click on the glyph play icon (
) at the top right position in order to open the Smart Tag.
b) Click on the Add Column link which opens a dialog that displays Column Collection Editor
c) Add the following columns as shown below
d) Now, run the application, the below output will occur
Let's take a deep dive and get insights into the properties that are available on Bunifu DataGrid View.

Appearance

Bunifu DataGrid View allows you to customize the appearance of your tabular data with ease. Here are the features that you can customize:

1. Built-In Themes

BunifuDataGridView offers 16+ different types of themes that you may utilize in your application. The Theme property allows you to get the property's value or set an enumerated theme value for your tabular data.
BunifuDataGridView exposes an array of properties that can be used to customize the theme. The following is a sampling of the properties related to our chosen theme:
In some cases, you may need to change some of the property values in your current theme. The AllowCustomTheming property allows you to get the property's boolean value or set a boolean value that, when set to true, will enable you to edit the property values that were used to design the theme you selected.
Property
Description
CurrentTheme
This property contains an array of properties that allows you to get or set the design attributes of the theme chosen with ease.
Let's take a deep dive to the CurrentTheme properties

a) GridColor

This property allows you to get or set a color value that will be applied on the grid lines separating the cells. It supports the use of RGB and HEX color values.

b) AlternatingRows

This property contains an array of properties that allow you to get or set the design attributes and styles associated with the odd rows.
Property
Description
BackColor
This property allows you to get or set the background color for each cell associated with odd rows. It supports the use of both RGB and HEX color values.
Font
This property allows you to get or set the font style for each cell's text in odd rows.
ForeColor
This property allows you to get or set the text color for each cell in an odd row.
SelectionBackColor
This property allows you to get or set the background color for each odd row cell, which gets applied when the row is selected. It supports the use of both RGB and HEX color values.
SelectionForeColor
This property allows you to get or set the text color for each odd row cell, which gets applied when the row is selected. It supports the use of both RGB and HEX color values.
C#
VB.NET
1
//set back color to the alternate row
2
bunifuDataGridView1.CurrentTheme.AlternatingRowsStyle.BackColor = Color.FromArgb(199, 226, 199);
3
//set text color to cells in the alternate row
4
bunifuDataGridView1.CurrentTheme.AlternatingRowsStyle.ForeColor = Color.Black;
5
//apply selection text color to cells im the alternate row
6
bunifuDataGridView1.CurrentTheme.AlternatingRowsStyle.SelectionForeColor = Color.White;
7
//set selection background color to the cells in the alternate row
8
bunifuDataGridView1.CurrentTheme.AlternatingRowsStyle.SelectionBackColor = Color.FromArgb(122, 185, 122);
9
//apply a font style to the cell's text in the alternate rows
10
bunifuDataGridView1.CurrentTheme.AlternatingRowsStyle.Font = new Font("Segoe UI", 10,FontStyle.Regular);
Copied!
1
'Apply back color to the alternate row
2
bunifuDataGridView1.CurrentTheme.AlternatingRowsStyle.BackColor = Color.FromArgb(199, 226, 199)
3
'Apply text color to cells in the alternate row
4
bunifuDataGridView1.CurrentTheme.AlternatingRowsStyle.ForeColor = Color.Black
5
'Apply selection text color to cells im the alternate row
6
bunifuDataGridView1.CurrentTheme.AlternatingRowsStyle.SelectionForeColor = Color.White
7
'Apply selection background color to the cells in the alternate row
8
bunifuDataGridView1.CurrentTheme.AlternatingRowsStyle.SelectionBackColor = Color.FromArgb(122, 185, 122)
9
'Apply a font style to the cell's text in the alternate rows
10
bunifuDataGridView1.CurrentTheme.AlternatingRowsStyle.Font = New Font("Segoe UI", 10,FontStyle.Regular)
11
Copied!

c) RowsStyle

This property contains an array of properties that allow you to get or set the design attributes and cell styles associated with a non-odd row in the data grid.
Below is a description of the properties that you can modify in the RowsStyle prop:
Property
Description
BackColor
This property allows you to get or set the background color for each cell of non-odd rows. It supports the use of both RGB and HEX color values.
Font
This property allows you to get or set the font style for each cell's text in non-odd rows.
ForeColor
This property allows you to get or set the text color for each cell's text in non-odd rows.
SelectionBackColor
This property allows you to get or set the background color for each non-odd row cell, which gets applied when the row is selected. It supports the use of both RGB and HEX color values.
SelectionForeColor
This property allows you to get or set the text color for each non-odd row cell, which gets applied when the row is selected. It supports the use of both RGB and HEX color values.
C#
VB.NET
1
//apply back color to the row
2
bunifuDataGridView1.CurrentTheme.RowsStyle.BackColor = Color.FromArgb(210, 231, 210);
3
//apply text color to cells in the row
4
bunifuDataGridView1.CurrentTheme.RowsStyle.ForeColor = Color.Black;
5
//set selection text color to cells in the row
6
bunifuDataGridView1.CurrentTheme.RowsStyle.SelectionForeColor = Color.White;
7
//set selection background color to the cells in the row
8
bunifuDataGridView1.CurrentTheme.RowsStyle.SelectionBackColor = Color.FromArgb(122, 185, 122);
9
//apply a font style to the cell's text in the row
10
bunifuDataGridView1.CurrentTheme.RowsStyle.Font = new Font("Segoe UI", 10, FontStyle.Regular);
Copied!
1
'Apply back color to the row
2
bunifuDataGridView1.CurrentTheme.RowsStyle.BackColor = Color.FromArgb(210, 231, 210)
3
'Apply text color to cells in the row
4
bunifuDataGridView1.CurrentTheme.RowsStyle.ForeColor = Color.Black
5
'Apply selection text color to cells in the row
6
bunifuDataGridView1.CurrentTheme.RowsStyle.SelectionForeColor = Color.White
7
'Apply selection background color to the cells in the row
8
bunifuDataGridView1.CurrentTheme.RowsStyle.SelectionBackColor = Color.FromArgb(122, 185, 122)
9
'Apply a font style to the cell's text in the row
10
bunifuDataGridView1.CurrentTheme.RowsStyle.Font = New Font("Segoe UI", 10, FontStyle.Regular)
11
Copied!

d) HeaderStyle

This property contains an array of properties that allow you to get or set the design attributes and styles associated with the column headers.
Below is a description of the properties that you can modify in the HeaderStyle prop:
Property
Description
BackColor
This property allows you to get or set the background color of each column header cell. It supports the use of both RGB and HEX color values.
Font
This property allows you to get or set the font style of the text in the column header cells.
ForeColor
This property allows you to get or set the color for the text in each column header cells.
SelectionBackColor
This property allows you to get or set the background color of the column's header cell, which will be applied when the column is selected. It supports the use of both RGB and HEX color values.
SelectionForeColor
This property allows you to get or set the color of text content in a column header cell, which will be applied when the column is selected. It supports the use of both RGB and HEX color values.
C#
VB.NET
1
//apply back color to the column header
2
bunifuDataGridView1.CurrentTheme.HeaderStyle.BackColor = Color.ForestGreen;
3
//set text color to cells in the column header
4
bunifuDataGridView1.CurrentTheme.HeaderStyle.ForeColor = Color.White;
5
//set selection text color to cells in the column header
6
bunifuDataGridView1.CurrentTheme.HeaderStyle.SelectionForeColor = Color.White;
7
//apply selection background color to the cells in the column
8
bunifuDataGridView1.CurrentTheme.HeaderStyle.SelectionBackColor = Color.FromArgb(27, 111, 27);
9
//set a font style to the cell's text in the column header
10
bunifuDataGridView1.CurrentTheme.HeaderStyle.Font = new Font("Segoe UI", 10, FontStyle.Regular);
11
//set the column header height
12
bunifuDataGridView1.ColumnHeadersHeight = 36;
Copied!
1
'apply back color to the column header
2
bunifuDataGridView1.CurrentTheme.HeaderStyle.BackColor = Color.ForestGreen
3
'set text color to cells in the column header
4
bunifuDataGridView1.CurrentTheme.HeaderStyle.ForeColor = Color.White
5
'set selection text color to cells in the column header
6
bunifuDataGridView1.CurrentTheme.HeaderStyle.SelectionForeColor = Color.White
7
'apply selection background color to the cells in the column
8
bunifuDataGridView1.CurrentTheme.HeaderStyle.SelectionBackColor = Color.FromArgb(27, 111, 27)
9
'set a font style to the cell's text in the column header
10
bunifuDataGridView1.CurrentTheme.HeaderStyle.Font = New Font("Segoe UI", 10, FontStyle.Regular)
11
'set the column header height
12
bunifuDataGridView1.ColumnHeadersHeight = 36
13
Copied!

2. Column properties

BunifuDataGridView provides you support for creating and editing both bound and unbound columns with ease. The Below section shows the various properties you can work with to design your column appearance and behavior.
Property name
Description
Columns
This property allows you to get the current collection of columns or set a column collection object containing an array of unbound columns for your tabular data.
The column collection editor is provided in the design view, and it allows you to view, add, update, and delete the existing columns. The columns to be added can be chosen from built-in column types or your own column.
Like the standard DataGridView, the created the unbound column gives you further ability to edit its properties. See how to get more insights on editing the properties provided in the column.
You also can add or edit different types of columns(e.g., Textbox columns, image view columns, e.t.c) using any language you prefer to code with( i.e., the C# and VB.NET languages).
Here's how you can add textbox columns through code:
C#
VB.NET
1
private void Form1_Load(object sender, EventArgs e)
2
{
3
bunifuDataGridView1.Columns.AddRange(
4
new DataGridViewTextBoxColumn()
5
{
6
HeaderText = "Product ID",
7
Name = "productIDColumn"
8
},
9
new DataGridViewTextBoxColumn()
10
{
11
HeaderText = "Product Name",
12
Name = "productNameColumn"
13
},
14
new DataGridViewTextBoxColumn()
15
{
16
HeaderText = "Customer Name",
17
Name = "customerNameColumn"
18
},
19
new DataGridViewTextBoxColumn()
20
{
21
HeaderText = "Country",
22
Name = "countryColumn"
23
},
24
new DataGridViewTextBoxColumn()
25
{
26
HeaderText = "Shipping City",
27
Name = "shippingCityColumn"
28
}
29
);
30
}
Copied!
1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
2
bunifuDataGridView1.Columns.AddRange(New DataGridViewTextBoxColumn() With {
3
.HeaderText = "Product ID",
4
.Name = "productIDColumn"
5
}, New DataGridViewTextBoxColumn() With {
6
.HeaderText = "Product Name",
7
.Name = "productNameColumn"
8
}, New DataGridViewTextBoxColumn() With {
9
.HeaderText = "Customer Name",
10
.Name = "customerNameColumn"
11
}, New DataGridViewTextBoxColumn() With {
12
.HeaderText = "Country",
13
.Name = "countryColumn"
14
}, New DataGridViewTextBoxColumn() With {
15
.HeaderText = "Shipping City",
16
.Name = "shippingCityColumn"
17
})
18
End Sub
19
Copied!
On running the code above, the below output will occur:
Alternatively, BunifuDataGridView can be bound to a data source, where the columns will be generated automatically. This will be discussed in further detail, later in this documentation.
The columns can be accessed through its column index or using its Name property from the bunifuDataGrid.Columns collection.
C#
VB.NET
1
DataGridViewColumn dataGridViewColumn = bunifuDataGridView1.Columns[0];
2
//or
3
DataGridViewColumn gridViewColumn = bunifuDataGridView1.Columns["productIDColumn"];
Copied!
1
Dim dataGridViewColumn As DataGridViewColumn = bunifuDataGridView1.Columns(0)
2
'or
3
Dim gridViewColumn As DataGridViewColumn = bunifuDataGridView1.Columns("productIDColumn")
4
Copied!
A column can be removed using the Remove and RemoveAt methods. The Clear method removes all columns from bunifuDataGrid.Columns collection.
C#
VB.NET
1
//remove the second column
2
bunifuDataGridView1.Columns.RemoveAt(1);
3
//or
4
bunifuDataGridView1.Columns.Remove(gridViewColumn);
5
//clear all columns
6
bunifuDataGridView1.Columns.Clear();
Copied!
1
'remove the second column
2
bunifuDataGridView1.Columns.RemoveAt(1)
3
'or
4
bunifuDataGridView1.Columns.Remove(gridViewColumn)
5
'clear all columns
6
bunifuDataGridView1.Columns.Clear()
7
Copied!
Property name
Description
ColumnHeadersDefaultCellStyle
This property allows you to get the style object applied in the columns or set a cell style object that contains an array of cell style properties that can change the appearance of the column header row.
Here are the properties that you can edit to the preferred style of your column header row.:
To ensure that the properties are working at runtime, ensure the AllowCustomTheming prop is set to true.
Property
Description
ColumnHeadersHeightSizeMode
This property allows you to get or set the behavior of adjusting the column headers' height during runtime. You can specify the following values: EnableResizing, DisableResizing, and AutoSize.
ColumnHeadersHeight
This property allows you to get or set an integer value that will resize the column header.
ColumnHeadersBorderStyle
This property allows you to get or set the border style applied to the column header.
ColumnHeadersVisible
This property allows you to get or set a boolean value that will hide the column header row when set to false. The default value is true.

3. Row properties

BunifuDataGridView enables you to add, populate, edit or remove rows for both bound and unbound data. Here are the properties you can use to design your rows, populate and edit your rows with ease:

Populating your rows:

It is very easy to populate rows with an unbound data with bunifuDataGridView.Rows collection property.
Rows are only populated at runtime. Also, note that to add the rows, you must have the columns in the first place.
Here's how you can add and populate a row in BunifuDataGridView using C# or VB.NET language. This example assumes that you have added 5 DataGridViewTextBoxColumn instances to BunifuDataGridView control's column collection.

Steps to create the unbound data:

Step one: Create the following class with the get and set properties:
C#
VB.NET
1
class Order
2
{
3
public string ProductId { get; set; }
4
public string ProductName { get; set; }
5
public string CustomerName { get; set; }
6
public string Country { get; set; }
7
public string ShippingCity{ get; set; }
8
}
Copied!
1
Friend Class Order
2
Public Property ProductId() As String
3
Public Property ProductName() As String
4
Public Property CustomerName() As String
5
Public Property Country() As String
6
Public Property ShippingCity() As String
7
End Class
8
Copied!
Step two: In your Form's Load event write the following code:
C#
VB.NET
1
using System;
2
using System.Collections.Generic;
3
using System.Windows.Forms;
4
namespace Example2
5
{
6
private void Form1_Load(object sender, EventArgs e)
7
{
8
List<Order> orderList = new List<Order>()
9
{
10
new Order()
11
{
12
ProductId = "#01293",
13
ProductName = "HP Envy x360",
14
CustomerName = "Dylan Gray",
15
Country = "Portugal",
16
ShippingCity = "Spain"
17
},
18
new Order()
19
{
20
ProductId = "#01294",
21
ProductName = "Seagate SSDs",
22
CustomerName = "Sarah Banks",
23
Country = "United States",
24
ShippingCity = "New York"
25
},
26
new Order()
27
{
28
ProductId = "#01295",
29
ProductName = "HP Envy x360",
30
CustomerName = "Tracy Rivera",
31
Country = "Kenya",
32
ShippingCity = "Nairobi"
33
}
34
};
35
foreach (var order in orderList)
36
{
37
bunifuDataGridView1.Rows.Add(order.ProductId,order.ProductName,order.CustomerName,order.Country,order.ShippingCity);
38
}
39
}
40
}
41
Copied!
1
Option Infer On
2
3
Imports System
4
Imports System.Collections.Generic
5
Imports System.Windows.Forms
6
Namespace Example2
7
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
8
Dim orderList As New List(Of Order)() From {
9
New Order() With {
10
.ProductId="#01293",
11
.ProductName="HP Envy x360",
12
.CustomerName="Dylan Gray",
13
.Country="Portugal",
14
.ShippingCity="Spain"
15
},
16
New Order() With {
17
.ProductId="#01294",
18
.ProductName="Seagate SSDs",
19
.CustomerName="Sarah Banks",
20
.Country="United States",
21
.ShippingCity="New York"
22
},
23
New Order() With {
24
.ProductId="#01295",
25
.ProductName="HP Envy x360",
26
.CustomerName="Tracy Rivera",
27
.Country="Kenya",
28
.ShippingCity="Nairobi"
29
}
30
}
31
For Each order In orderList
32
bunifuDataGridView1.Rows.Add(order.ProductId,order.ProductName,order.CustomerName,order.Country,order.ShippingCity)
33
Next order
34
End Sub
35
End Namespace
36
Copied!
Now, after running your application with the codes above, the following output will occur:
You can also use the Rows collection to modify the values in the control or to remove rows. The following example shows you how to modify cell values programmatically.
C#
VB.NET
1
//Modify the value in the second cell of the third row.
2
bunifuDataGridView1.Rows[2].Cells[1].Value = "Dell AlienWare M17 R4";
3
// The previous line is equivalent to the following line.
4
bunifuDataGridView1[1,2].Value= "Dell AlienWare M17 R4";
Copied!
1
'Modify the value in the second cell of the third row.
2
bunifuDataGridView1.Rows(2).Cells(1).Value = "Dell AlienWare M17 R4"
3
' The previous line is equivalent to the following line.
4
bunifuDataGridView1(1,2).Value= "Dell AlienWare M17 R4"
5
Copied!

Styling a row cell

The appearance of a BunifuDataGrid cell can be customized using the bunifuDataGridView.Rows collection Style property. We have the option to style the back color, its selection color, the font, its forecolor, and the alignment of text in a particular cell.
The following example shows you how to style the appearance of a cell back color programmatically. The assumption is that you already have some data in your table.
C#
VB.NET
1
for(int i = 0; i < bunifuDataGridView1.Rows.Count; i++)
2
{
3
//Modify the backcolor, the fore color and selection color in every cell of the FIRST column
4
bunifuDataGridView1[1, i].Style.BackColor = Color.FromArgb(152, 175, 92);
5
bunifuDataGridView1[1, i].Style.ForeColor = Color.White;
6
bunifuDataGridView1[1, i].Style.SelectionBackColor = Color.FromArgb(63, 137, 90);
7
//Modify the backcolor, the fore color and selection color every cell of the THIRD column
8
bunifuDataGridView1[4, i].Style.BackColor = Color.FromArgb(152, 175, 92);
9
bunifuDataGridView1[4, i].Style.ForeColor = Color.White;
10
bunifuDataGridView1[4, i].Style.SelectionBackColor = Color.FromArgb(63, 137, 90);
11
}
Copied!
1
For i As Integer = 0 To bunifuDataGridView1.Rows.Count - 1
2
'Modify the backcolor, the fore color and selection color in every cell of the FIRST column
3
bunifuDataGridView1(1, i).Style.BackColor = Color.FromArgb(152, 175, 92)
4
bunifuDataGridView1(1, i).Style.ForeColor = Color.White
5
bunifuDataGridView1(1, i).Style.SelectionBackColor = Color.FromArgb(63, 137, 90)
6
'Modify the backcolor, the fore color and selection color every cell of the THIRD column
7
bunifuDataGridView1(4, i).Style.BackColor = Color.FromArgb(152, 175, 92)
8
bunifuDataGridView1(4, i).Style.ForeColor = Color.White
9
bunifuDataGridView1(4, i).Style.SelectionBackColor = Color.FromArgb(63, 137, 90)
10
Next i
11
Copied!
The above code will output the occurrence below:

4. Selection

BunifuDataGrid enables you to select a single row or cell or multiple rows or cells. Sometimes you want your application to perform actions such as printing out the selected rows or columns based on user selections within the tabular control. Depending on the actions, you may want to restrict the kinds of selection that are possible.
This section will explain the types of selection available for GridControl and its usability.

a) Row selection

You can specify a full row type of selection by setting the BunifuDataGridView.SelectionMode property to FullRowSelect.
When a cell or row header is clicked in the DataGrid, an entire row selection is created.
By default, users can select multiple rows, columns, or cells by dragging with the mouse, pressing CTRL or SHIFT keys while selecting to extend or modify a selection. To prevent this behavior set the MultiSelect property to false.
To retrieve the selected values in a row, refer to the following code:
C#
VB.NET
1
private void bunifuButton1_Click(object sender, EventArgs e)
2
{
3
//get the number of the selected rows
4
int selectedRows = bunifuDataGridView1.Rows.GetRowCount(DataGridViewElementStates.Selected);
5
6
if (selectedRows > 0)
7
{
8
StringBuilder cellValuesStringBuilder = new StringBuilder();
9
//loop through each of the selected row
10
for(int i = 0; i < selectedRows; i++)
11
{
12
//loop the cells of a row, get their values and append them in a string builder
13
for (int j = 0; j < bunifuDataGridView1.ColumnCount; j++)
14
{
15
cellValuesStringBuilder.Append(bunifuDataGridView1.SelectedRows[i].Cells[j].Value+"\t");
16
}
17
//create a new line for the next row loop
18
cellValuesStringBuilder.Append("\n");
19
}
20
//print the output on a console
21
Console.WriteLine(cellValuesStringBuilder);
22
}
23
}
Copied!
1
Private Sub bunifuButton1_Click(ByVal sender As Object, ByVal e As EventArgs)
2
'get the number of the selected rows
3
Dim selectedRows As Integer = bunifuDataGridView1.Rows.GetRowCount(DataGridViewElementStates.Selected)
4
5
If selectedRows > 0 Then
6
Dim cellValuesStringBuilder As New StringBuilder()
7
'loop through each of the selected row
8
For i As Integer = 0 To selectedRows - 1
9
'loop the cells of a row, get their values and append them in a string builder
10
For j As Integer = 0 To bunifuDataGridView1.ColumnCount - 1
11
cellValuesStringBuilder.Append(bunifuDataGridView1.SelectedRows(i).Cells(j).Value & vbTab)
12
Next j
13
'create a new line for the next row loop
14
cellValuesStringBuilder.Append(vbLf)
15
Next i
16
'print the output on a console
17
Console.WriteLine(cellValuesStringBuilder)
18
End If
19
End Sub
20
Copied!
The selected values are printed in the output screen as follows:

b) Cell selection

A cell selection is specified by setting BunifuDataGridView.Selection property to CellSelect. When a user clicks on a cell, a selection is created on that cell.
The following image shows for multiple mode cell selection:
Here's a code that retrieves the selected cell values:
C#
1
private void bunifuButton1_Click(object sender, EventArgs e){
2
//get the number of selected cells
3
int selectedCells = bunifuDataGridView1.GetCellCount(DataGridViewElementStates.Selected);
4
5
if (selectedCells > 0)
6
{
7
StringBuilder cellStrBuilder = new StringBuilder();
8
//loop through the selected cells, get their values and append to the string builder variable
9
for(int i = 0; i < selectedCells; i++)
10
{
11
cellStrBuilder.Append(bunifuDataGridView1.SelectedCells[i].Value + "\t");
12
}
13
//output the seleccted cell values
14
Console.WriteLine(cellStrBuilder);
15
}
Copied!
The selected values are printed in the output screen as follows:

c) Header column selection

BunifuDataGridView allows you to select or deselect rows within a specific column by interacting with the column's header cell. To set this type of selection set the SelectionMode prop to ColumnHeaderSelect.
To make this type of selection work, ensure that the SortMode property for the textbox columns is set to programmatic. The sorting techniques will be discussed in greater detail later in this documentation.
To retrieve the selected values in a row, refer to the following code:
C#
VB.NET
1
private void Form3_Load(object sender, EventArgs e)
2
{
3
for (int i = 0; i < bunifuDataGridView1.Columns.Count; i++)
4
{
5
//set the sort mode for all the textbox columns
6
bunifuDataGridView1.Columns(i).SortMode = DataGridViewColumnSortMode.Programmatic;
7
}
8
bunifuDataGridView1.SelectionMode = DataGridViewSelectionMode.ColumnHeaderSelect;
9
}
10
private void bunifuButton1_Click(object sender, EventArgs e)
11
{ // get the selected cells in the column
12
int selectedCells = bunifuDataGridView1.GetCellCount(DataGridViewElementStates.Selected);
13
StringBuilder strBuider = new StringBuilder();
14
15
for (int i = 0; i < selectedCells; i++)
16
{
17
//get the selected cell values from the column
18
strBuider.Append(bunifuDataGridView1.SelectedCells(i).Value + "\t");
19
}
20
//output the selected values
21
Console.WriteLine(strBuider);
22
}
23
Copied!
1
Imports Microsoft.VisualBasic
2
3
Private Sub Form3_Load(ByVal sender As Object, ByVal e As EventArgs)
4
For i As Integer = 0 To bunifuDataGridView1.Columns.Count - 1
5
bunifuDataGridView1.Columns(i).SortMode = DataGridViewColumnSortMode.Programmatic
6
Next i
7
bunifuDataGridView1.SelectionMode = DataGridViewSelectionMode.ColumnHeaderSelect
8
End Sub
9
Private Sub bunifuButton1_Click(ByVal sender As Object, ByVal e As EventArgs)
10
Dim selectedCells As Integer = bunifuDataGridView1.GetCellCount(DataGridViewElementStates.Selected)
11
Dim strBuider As New StringBuilder()
12
13
For i As Integer = 0 To selectedCells - 1
14
strBuider.Append(bunifuDataGridView1.SelectedCells(i).Value & vbTab)
15
Next i
16
Console.WriteLine(strBuider)
17
End Sub
18
Copied!

d) Disable selection

The selection can be disabled by setting the Enabled property to False.
When the Datagrid control is disabled, it becomes a read-only control.

5. Custom Tooltips

There are instances where Datagrid cells contain extensive text content, and this information is hidden due to the cell's size. As a result, ToolTips are added to provide support for displaying the entire text content in a pop-up window that appears when the mouse hovers over the cells of a BunifuDataGrid.
The steps below demonstrate how we will override the standard DataGrid tooltip and replace it with a more customizable Bunifu tooltip control. It is assumed that you already have a Datagrid with data in its cells.
Step one: Drag and drop a Bunifu Tooltip control in the form.
Step two: Access the properties of BunifuDataGrid and look out for the ShowCellTooltipsproperty. Set it to false. This will enable us to add our own custom tooltip.
Step three: Go to the event properties of BunifuDataGrid and look out for the CellMouseEnter event. Double-click on its text area to navigate to the code view.
Step four: Write the following code:
C#
VB.NET
1
//the event gets fired when the mouse is over the cell
2
private void bunifuDataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
3
{
4
/*
5
* check whether the mouse is over the row cells of the datagrid.
6
* this avoids the code below from executing when the mouse hovers on the column header cells and row header cells
7
*/
8
if(e.ColumnIndex >= 0 & e.RowIndex >= 0)
9
{
10
//get the row datagrid cell currently hovered
11
DataGridViewCell dataGridcell = bunifuDataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
12
//get the display area or the location of the cell that is currently hovered
13
var cellreactangle = bunifuDataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);
14
//check whether the cell has text content in it
15
if (dataGridcell.Value != null)
16
{
17
//use bunifu tooltip to display the text content of the cell
18
bunifuToolTip1.Show(bunifuDataGridView1, dataGridcell.Value.ToString(), bunifuDataGridView1.Columns[dataGridcell.ColumnIndex].HeaderText, null, bunifuDataGridView1.PointToScreen(new Point(cellreactangle.X + 80, cellreactangle.Y)));
19
}
20
}
21
}
22
private void bunifuDataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
23
{
24
bunifuToolTip1.Hide();
25
}
Copied!
1
Option Infer On
2
3
'the event gets fired when the mouse is over the cell
4
Private Sub bunifuDataGridView1_CellMouseEnter(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs)
5
'
6
' * check whether the mouse is over the row cells of the datagrid.
7
' * this avoids the code below from executing when the mouse hovers on the column header cells and row header cells
8
'
9
If e.ColumnIndex >= 0 And e.RowIndex >= 0 Then
10
'get the row datagrid cell currently hovered
11
Dim dataGridcell As DataGridViewCell = bunifuDataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex)
12
'get the display area or the location of the cell that is currently hovered
13
Dim cellreactangle = bunifuDataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, True)
14
'check whether the cell has text content in it
15
If dataGridcell.Value IsNot Nothing Then
16
'use bunifu tooltip to display the text content of the cell
17
bunifuToolTip1.Show(