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.
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.
Imports SystemImports Bunifu.UI.WinFormsImports System.DrawingImports System.Windows.FormsNamespace BunifuGrid Partial Public Class Form1 Inherits Form Public Sub New()InitializeComponent() End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Dim bunifuDataGridView As New BunifuDataGridView() bunifuDataGridView.Size = New Size(600,250) bunifuDataGridView.Location = New Point(12,28) Me.Controls.Add(bunifuDataGridView) bunifuDataGridView.PopulateWithSampleData() End Sub End ClassEnd Namespace
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:
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.
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.
//set back color to the alternate rowbunifuDataGridView1.CurrentTheme.AlternatingRowsStyle.BackColor=Color.FromArgb(199,226,199);//set text color to cells in the alternate rowbunifuDataGridView1.CurrentTheme.AlternatingRowsStyle.ForeColor=Color.Black;//apply selection text color to cells im the alternate rowbunifuDataGridView1.CurrentTheme.AlternatingRowsStyle.SelectionForeColor=Color.White;//set selection background color to the cells in the alternate rowbunifuDataGridView1.CurrentTheme.AlternatingRowsStyle.SelectionBackColor=Color.FromArgb(122,185,122);//apply a font style to the cell's text in the alternate rowsbunifuDataGridView1.CurrentTheme.AlternatingRowsStyle.Font=newFont("Segoe UI",10,FontStyle.Regular);
'Apply back color to the alternate rowbunifuDataGridView1.CurrentTheme.AlternatingRowsStyle.BackColor = Color.FromArgb(199, 226, 199)'Apply text color to cells in the alternate rowbunifuDataGridView1.CurrentTheme.AlternatingRowsStyle.ForeColor = Color.Black'Apply selection text color to cells im the alternate rowbunifuDataGridView1.CurrentTheme.AlternatingRowsStyle.SelectionForeColor = Color.White'Apply selection background color to the cells in the alternate rowbunifuDataGridView1.CurrentTheme.AlternatingRowsStyle.SelectionBackColor = Color.FromArgb(122,185,122)'Apply a font style to the cell's text in the alternate rowsbunifuDataGridView1.CurrentTheme.AlternatingRowsStyle.Font = New Font("Segoe UI",10,FontStyle.Regular)
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:
//apply back color to the rowbunifuDataGridView1.CurrentTheme.RowsStyle.BackColor=Color.FromArgb(210,231,210);//apply text color to cells in the rowbunifuDataGridView1.CurrentTheme.RowsStyle.ForeColor=Color.Black;//set selection text color to cells in the rowbunifuDataGridView1.CurrentTheme.RowsStyle.SelectionForeColor=Color.White;//set selection background color to the cells in the rowbunifuDataGridView1.CurrentTheme.RowsStyle.SelectionBackColor=Color.FromArgb(122,185,122);//apply a font style to the cell's text in the rowbunifuDataGridView1.CurrentTheme.RowsStyle.Font=newFont("Segoe UI",10,FontStyle.Regular);
'Apply back color to the rowbunifuDataGridView1.CurrentTheme.RowsStyle.BackColor = Color.FromArgb(210, 231, 210)'Apply text color to cells in the rowbunifuDataGridView1.CurrentTheme.RowsStyle.ForeColor = Color.Black'Apply selection text color to cells in the rowbunifuDataGridView1.CurrentTheme.RowsStyle.SelectionForeColor = Color.White'Apply selection background color to the cells in the rowbunifuDataGridView1.CurrentTheme.RowsStyle.SelectionBackColor = Color.FromArgb(122,185,122)'Apply a font style to the cell's text in the rowbunifuDataGridView1.CurrentTheme.RowsStyle.Font = New Font("Segoe UI",10, FontStyle.Regular)
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:
//apply back color to the column headerbunifuDataGridView1.CurrentTheme.HeaderStyle.BackColor=Color.ForestGreen;//set text color to cells in the column headerbunifuDataGridView1.CurrentTheme.HeaderStyle.ForeColor=Color.White;//set selection text color to cells in the column headerbunifuDataGridView1.CurrentTheme.HeaderStyle.SelectionForeColor=Color.White;//apply selection background color to the cells in the columnbunifuDataGridView1.CurrentTheme.HeaderStyle.SelectionBackColor=Color.FromArgb(27,111,27);//set a font style to the cell's text in the column headerbunifuDataGridView1.CurrentTheme.HeaderStyle.Font=newFont("Segoe UI",10,FontStyle.Regular);//set the column header heightbunifuDataGridView1.ColumnHeadersHeight=36;
'apply back color to the column headerbunifuDataGridView1.CurrentTheme.HeaderStyle.BackColor = Color.ForestGreen'set text color to cells in the column headerbunifuDataGridView1.CurrentTheme.HeaderStyle.ForeColor = Color.White'set selection text color to cells in the column headerbunifuDataGridView1.CurrentTheme.HeaderStyle.SelectionForeColor = Color.White'apply selection background color to the cells in the columnbunifuDataGridView1.CurrentTheme.HeaderStyle.SelectionBackColor = Color.FromArgb(27,111,27)'set a font style to the cell's text in the column headerbunifuDataGridView1.CurrentTheme.HeaderStyle.Font = New Font("Segoe UI",10, FontStyle.Regular)'set the column header heightbunifuDataGridView1.ColumnHeadersHeight = 36
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.
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:
privatevoidForm1_Load(object sender,EventArgs e){bunifuDataGridView1.Columns.AddRange(newDataGridViewTextBoxColumn() { HeaderText ="Product ID", Name ="productIDColumn" },newDataGridViewTextBoxColumn() { HeaderText ="Product Name", Name ="productNameColumn" },newDataGridViewTextBoxColumn() { HeaderText ="Customer Name", Name ="customerNameColumn" },newDataGridViewTextBoxColumn() { HeaderText ="Country", Name ="countryColumn" },newDataGridViewTextBoxColumn() { HeaderText ="Shipping City", Name ="shippingCityColumn" } );}
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) bunifuDataGridView1.Columns.AddRange(New DataGridViewTextBoxColumn() With { .HeaderText ="Product ID", .Name ="productIDColumn" }, New DataGridViewTextBoxColumn() With { .HeaderText ="Product Name", .Name ="productNameColumn" }, New DataGridViewTextBoxColumn() With { .HeaderText ="Customer Name", .Name ="customerNameColumn" }, New DataGridViewTextBoxColumn() With { .HeaderText ="Country", .Name ="countryColumn" }, New DataGridViewTextBoxColumn() With { .HeaderText ="Shipping City", .Name ="shippingCityColumn" })End Sub
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.
Dim dataGridViewColumn As DataGridViewColumn = bunifuDataGridView1.Columns(0)'orDim gridViewColumn As DataGridViewColumn = bunifuDataGridView1.Columns("productIDColumn")
A column can be removed using the Remove and RemoveAt methods. The Clear method removes all columns from bunifuDataGrid.Columns collection.
//remove the second columnbunifuDataGridView1.Columns.RemoveAt(1);//orbunifuDataGridView1.Columns.Remove(gridViewColumn);//clear all columnsbunifuDataGridView1.Columns.Clear();
'remove the second columnbunifuDataGridView1.Columns.RemoveAt(1)'orbunifuDataGridView1.Columns.Remove(gridViewColumn)'clear all columnsbunifuDataGridView1.Columns.Clear()
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.
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:
Friend Class Order Public Property ProductId() As String Public Property ProductName() As String Public Property CustomerName() As String Public Property Country() As String Public Property ShippingCity() As StringEnd Class
Step two: In your Form's Load eventwrite the following code:
Option Infer OnImports SystemImports System.Collections.GenericImports System.Windows.FormsNamespace Example2Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Dim orderList As New List(Of Order)() From { New Order() With { .ProductId="#01293", .ProductName="HP Envy x360", .CustomerName="Dylan Gray", .Country="Portugal", .ShippingCity="Spain" }, New Order() With { .ProductId="#01294", .ProductName="Seagate SSDs", .CustomerName="Sarah Banks", .Country="United States", .ShippingCity="New York" }, New Order() With { .ProductId="#01295", .ProductName="HP Envy x360", .CustomerName="Tracy Rivera", .Country="Kenya", .ShippingCity="Nairobi" } }For Each order In orderList bunifuDataGridView1.Rows.Add(order.ProductId,order.ProductName,order.CustomerName,order.Country,order.ShippingCity)Next orderEnd SubEnd Namespace
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.
//Modify the value in the second cell of the third row.bunifuDataGridView1.Rows[2].Cells[1].Value="Dell AlienWare M17 R4";// The previous line is equivalent to the following line. bunifuDataGridView1[1,2].Value="Dell AlienWare M17 R4";
'Modify the value in the second cell of the third row.bunifuDataGridView1.Rows(2).Cells(1).Value = "Dell AlienWare M17 R4"' The previous line is equivalent to the following line. bunifuDataGridView1(1,2).Value="Dell AlienWare M17 R4"
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.
for(int i =0; i <bunifuDataGridView1.Rows.Count; i++){ //Modify the backcolor, the fore color and selection color in every cell of the FIRST columnbunifuDataGridView1[1, i].Style.BackColor=Color.FromArgb(152,175,92);bunifuDataGridView1[1, i].Style.ForeColor=Color.White;bunifuDataGridView1[1, i].Style.SelectionBackColor=Color.FromArgb(63,137,90); //Modify the backcolor, the fore color and selection color every cell of the THIRD columnbunifuDataGridView1[4, i].Style.BackColor=Color.FromArgb(152,175,92);bunifuDataGridView1[4, i].Style.ForeColor=Color.White;bunifuDataGridView1[4, i].Style.SelectionBackColor=Color.FromArgb(63,137,90);}
For i As Integer =0 To bunifuDataGridView1.Rows.Count -1 'Modify the backcolor, the fore color and selection color in every cell of the FIRST column bunifuDataGridView1(1, i).Style.BackColor = Color.FromArgb(152, 175, 92) bunifuDataGridView1(1, i).Style.ForeColor = Color.White bunifuDataGridView1(1, i).Style.SelectionBackColor = Color.FromArgb(63, 137, 90) 'Modify the backcolor, the fore color and selection color every cell of the THIRD columnbunifuDataGridView1(4, i).Style.BackColor = Color.FromArgb(152,175,92)bunifuDataGridView1(4, i).Style.ForeColor = Color.WhitebunifuDataGridView1(4, i).Style.SelectionBackColor = Color.FromArgb(63,137,90)Next i
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:
privatevoidbunifuButton1_Click(object sender,EventArgs e){ //get the number of the selected rowsint selectedRows =bunifuDataGridView1.Rows.GetRowCount(DataGridViewElementStates.Selected);if (selectedRows >0) {StringBuilder cellValuesStringBuilder =newStringBuilder(); //loop through each of the selected rowfor(int i =0; i < selectedRows; i++) { //loop the cells of a row, get their values and append them in a string builderfor (int j =0; j <bunifuDataGridView1.ColumnCount; j++) {cellValuesStringBuilder.Append(bunifuDataGridView1.SelectedRows[i].Cells[j].Value+"\t"); } //create a new line for the next row loopcellValuesStringBuilder.Append("\n"); } //print the output on a consoleConsole.WriteLine(cellValuesStringBuilder); }}
Private Sub bunifuButton1_Click(ByVal sender As Object, ByVal e As EventArgs) 'get the number of the selected rows Dim selectedRows As Integer = bunifuDataGridView1.Rows.GetRowCount(DataGridViewElementStates.Selected) If selectedRows > 0 Then Dim cellValuesStringBuilder As New StringBuilder() 'loop through each of the selected row For i As Integer =0 To selectedRows -1 'loop the cells of a row, get their values and append them in a string builder For j As Integer = 0 To bunifuDataGridView1.ColumnCount - 1 cellValuesStringBuilder.Append(bunifuDataGridView1.SelectedRows(i).Cells(j).Value & vbTab) Next j 'create a new line for the next row loop cellValuesStringBuilder.Append(vbLf) Next i 'print the output on a console Console.WriteLine(cellValuesStringBuilder) End IfEnd Sub
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:
privatevoidbunifuButton1_Click(object sender,EventArgs e){//get the number of selected cellsint selectedCells =bunifuDataGridView1.GetCellCount(DataGridViewElementStates.Selected);if (selectedCells >0){StringBuilder cellStrBuilder =newStringBuilder(); //loop through the selected cells, get their values and append to the string builder variablefor(int i =0; i < selectedCells; i++) {cellStrBuilder.Append(bunifuDataGridView1.SelectedCells[i].Value+"\t"); } //output the seleccted cell valuesConsole.WriteLine(cellStrBuilder);}
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:
privatevoidForm3_Load(object sender,EventArgs e){for (int i =0; i <bunifuDataGridView1.Columns.Count; i++) { //set the sort mode for all the textbox columnsbunifuDataGridView1.Columns(i).SortMode=DataGridViewColumnSortMode.Programmatic; }bunifuDataGridView1.SelectionMode=DataGridViewSelectionMode.ColumnHeaderSelect;}privatevoidbunifuButton1_Click(object sender,EventArgs e){ // get the selected cells in the columnint selectedCells =bunifuDataGridView1.GetCellCount(DataGridViewElementStates.Selected);StringBuilder strBuider =newStringBuilder();for (int i =0; i < selectedCells; i++) { //get the selected cell values from the columnstrBuider.Append(bunifuDataGridView1.SelectedCells(i).Value+"\t"); } //output the selected valuesConsole.WriteLine(strBuider);}
Imports Microsoft.VisualBasicPrivate Sub Form3_Load(ByVal sender As Object, ByVal e As EventArgs) For i As Integer =0 To bunifuDataGridView1.Columns.Count -1 bunifuDataGridView1.Columns(i).SortMode = DataGridViewColumnSortMode.Programmatic Next i bunifuDataGridView1.SelectionMode = DataGridViewSelectionMode.ColumnHeaderSelectEnd SubPrivate Sub bunifuButton1_Click(ByVal sender As Object, ByVal e As EventArgs) Dim selectedCells As Integer = bunifuDataGridView1.GetCellCount(DataGridViewElementStates.Selected) Dim strBuider As New StringBuilder() For i As Integer =0 To selectedCells -1 strBuider.Append(bunifuDataGridView1.SelectedCells(i).Value & vbTab) Next i Console.WriteLine(strBuider)End Sub
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:
//the event gets fired when the mouse is over the cellprivatevoidbunifuDataGridView1_CellMouseEnter(object sender,DataGridViewCellEventArgs e){/* * check whether the mouse is over the row cells of the datagrid. * this avoids the code below from executing when the mouse hovers on the column header cells and row header cells
*/if(e.ColumnIndex>=0&e.RowIndex>=0) { //get the row datagrid cell currently hoveredDataGridViewCell dataGridcell =bunifuDataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex]; //get the display area or the location of the cell that is currently hoveredvar cellreactangle =bunifuDataGridView1.GetCellDisplayRectangle(e.ColumnIndex,e.RowIndex,true); //check whether the cell has text content in itif (dataGridcell.Value!=null) { //use bunifu tooltip to display the text content of the cell bunifuToolTip1.Show(bunifuDataGridView1, dataGridcell.Value.ToString(), bunifuDataGridView1.Columns[dataGridcell.ColumnIndex].HeaderText, null, bunifuDataGridView1.PointToScreen(new Point(cellreactangle.X + 80, cellreactangle.Y)));
} } }privatevoidbunifuDataGridView1_CellMouseLeave(object sender,DataGridViewCellEventArgs e){bunifuToolTip1.Hide();}
Option Infer On'the event gets fired when the mouse is over the cellPrivate Sub bunifuDataGridView1_CellMouseEnter(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs)' ' * check whether the mouse is over the row cells of the datagrid.' * this avoids the code below from executing when the mouse hovers on the column header cells and row header cells
' If e.ColumnIndex >=0 And e.RowIndex >=0 Then 'get the row datagrid cell currently hovered Dim dataGridcell As DataGridViewCell = bunifuDataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex) 'get the display area or the location of the cell that is currently hovered Dim cellreactangle = bunifuDataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, True) 'check whether the cell has text content in it If dataGridcell.Value IsNot Nothing Then 'use bunifu tooltip to display the text content of the cell bunifuToolTip1.Show(bunifuDataGridView1, dataGridcell.Value.ToString(), "08/07/2021", Nothing, bunifuDataGridView1.PointToScreen(New Point(cellreactangle.X + 80, cellreactangle.Y)))
End If End IfEnd SubPrivate Sub bunifuDataGridView1_CellMouseLeave(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) bunifuToolTip1.Hide()End Sub
Step 5: Run your application. Here's is an example of our application running the codes above, the following output will occur:
Data Binding
BunifuDataGrid has been designed to support the use of bounded data.
Let us examine each feature in detail to ensure that we are maximizing the use of bounded data properties, methods, and events to the fullest extent possible.
Bunifu DataGrid View has data-binding support to work out-of-the-box with all popular data sources like SQL Server, Oracle, DataTable, and IEnumerable, and data providers like LINQ to SQL, ADO.NET, Entity Framework, and WCF Data Service.
If the data source implements the INotifyCollectionChanged interface, then BunifuDataGridView will automatically refresh the UI when an item is added, removed, or while the list cleared.
1. Binding to a Generic Collection List
It's simple and clear to create a generic collection with binding properties, which results in bounded data. The following code illustrates how we can bind a collection of list objects with the BindingList Class to create tabular data for BunifuDataGridView
Note that the column header names will be created automatically based on the property names given to the class objects.
Step 1: Create the following OrderDemo class with its get and set properties:
Public Class DemoOrder Private order_Id As Guid=Guid.NewGuid() Public Property OrderID() As Guid Get Return order_Id End GetSet(ByVal value As Guid) order_Id = value End Set End Property Public Property ProductName() As String Public Property CustomerName() As String Public Property PhoneNumber() As String Public Property ShippingCity() As StringEnd Class
Step 2: In the form load event of your form write the following code:
//the global variable provides the source of data for the Datagrid and where the generic list will be boundBindingSource bindingSource =newBindingSource();//the form load event containing out BunifuDataGridViewprivatevoidForm1_Load(object sender,EventArgs e){/* *the BindingList class is of type OrderDemo *has support to provide binding capabilities for a generic list */BindingList<OrderDemo> orderDemoList =newBindingList<OrderDemo>() { //add the class objects to the list, setting their propertiesnewOrderDemo() { CustomerName="Tracy Ravis", PhoneNumber="(188)1863076", ShippingCity="Salt Lake City", ProductName="HP Envy x360 13 (2020)" },newOrderDemo() { CustomerName="Elsie Harris", PhoneNumber="(046)1938785", ShippingCity="Perth", ProductName="HP Envy 13 (2021)" },newOrderDemo() { CustomerName="Roger Craig", PhoneNumber="(042)9830172", ShippingCity="Australian Capital Territory", ProductName="HP Spectre x360 14" },newOrderDemo() { CustomerName="Danny Mckinney", PhoneNumber="(651)0438562", ShippingCity="Glendale", ProductName="HP EliteBook x360 1040 G7" },newOrderDemo() { CustomerName="Derrick Wade", PhoneNumber="(636)4728149", ShippingCity="San Bernardino", ProductName="HP Chromebook x2" } }; //bind the list to the binding sourcebindingSource.DataSource= orderDemoList; //set the binding source as the data source for Bunifu DataGrid ViewbunifuDataGridView1.DataSource= bindingSource;}
'the global variable provides the source of data for the Datagrid and where the generic list will be boundPrivate bindingSource As New BindingSource()'the form load event containing out BunifuDataGridViewPrivate Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)' ' *the BindingList class is of type OrderDemo' *has support to provide binding capabilities for a generic list' Dim orderDemoList As New BindingList(Of OrderDemo)() From { New OrderDemo() With { .CustomerName="Tracy Ravis", .PhoneNumber="(188)1863076", .ShippingCity="Salt Lake City", .ProductName="HP Envy x360 13 (2020)" }