merge main branch

This commit is contained in:
CXWTool Service Account
2021-12-02 06:01:01 +00:00
42 changed files with 579 additions and 81 deletions
@@ -1,5 +1,8 @@
---
title: Create an Unbound DataGridView Control
title: How to Create an Unbound Windows Forms DataGridView Control
description: Populate an unbound Windows Forms DataGridView Control programmatically and display a small amount of data in a table format without binding it to a data source
ms.date: "03/30/2017"
dev_langs:
- "csharp"
@@ -11,18 +14,21 @@ helpviewer_keywords:
ms.assetid: b5d4b47d-9a28-4d88-9dba-0a3c90fba71d
---
# How to: Create an Unbound Windows Forms DataGridView Control
The following code example demonstrates how to populate a <xref:System.Windows.Forms.DataGridView> control programmatically without binding it to a data source. This is useful when you have a small amount of data that you want to display in a table format.
The following code example demonstrates how to populate a <xref:System.Windows.Forms.DataGridView> control programmatically without binding it to a data source. This is useful when you have a small amount of data that you want to display in a table format.
For a complete explanation of this code example, see [Walkthrough: Creating an Unbound Windows Forms DataGridView Control](walkthrough-creating-an-unbound-windows-forms-datagridview-control.md).
For a complete explanation of this code example, see [Walkthrough: Creating an Unbound Windows Forms DataGridView Control](walkthrough-creating-an-unbound-windows-forms-datagridview-control.md).
## Example
## Example
[!code-csharp[System.Windows.Forms.DataGridViewSimpleUnbound#00](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.DataGridViewSimpleUnbound/CS/simpleunbound.cs#00)]
[!code-vb[System.Windows.Forms.DataGridViewSimpleUnbound#00](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.DataGridViewSimpleUnbound/VB/simpleunbound.vb#00)]
[!code-vb[System.Windows.Forms.DataGridViewSimpleUnbound#00](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.DataGridViewSimpleUnbound/VB/simpleunbound.vb#00)]
## Compiling the Code
This example requires:
## Compiling the Code
This example requires:
- References to the System, System.Drawing, and System.Windows.Forms assemblies.
- References to the System, System.Drawing, and System.Windows.Forms assemblies.
## See also
@@ -1,5 +1,8 @@
---
title: Create an Unbound DataGridView Control
title: Walkthrough to Creating an Unbound Windows Forms DataGridView Control
description: You can create an Unbound Windows Forms DataGridView Control and display a small amount of data without binding it to a data source
ms.date: "03/30/2017"
dev_langs:
- "csharp"
@@ -13,13 +16,14 @@ helpviewer_keywords:
ms.assetid: 5a8d6afa-1b4b-4b24-8db8-501086ffdebe
---
# Walkthrough: Creating an Unbound Windows Forms DataGridView Control
You may frequently want to display tabular data that does not originate from a database. For example, you may want to show the contents of a two-dimensional array of strings. The <xref:System.Windows.Forms.DataGridView> class provides an easy and highly customizable way to display data without binding to a data source. This walkthrough shows how to populate a <xref:System.Windows.Forms.DataGridView> control and manage the addition and deletion of rows in "unbound" mode. By default, the user can add new rows. To prevent row addition, set the <xref:System.Windows.Forms.DataGridView.AllowUserToAddRows%2A> property is `false`.
To copy the code in this topic as a single listing, see [How to: Create an Unbound Windows Forms DataGridView Control](how-to-create-an-unbound-windows-forms-datagridview-control.md).
## Creating the Form
#### To use an unbound DataGridView control
### To use an unbound DataGridView control
1. Create a class that derives from <xref:System.Windows.Forms.Form> and contains the following variable declarations and `Main` method.
@@ -64,16 +68,18 @@ You may frequently want to display tabular data that does not originate from a d
[!code-csharp[System.Windows.Forms.DataGridViewSimpleUnbound#10](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.DataGridViewSimpleUnbound/CS/simpleunbound.cs#10)]
[!code-vb[System.Windows.Forms.DataGridViewSimpleUnbound#10](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.DataGridViewSimpleUnbound/VB/simpleunbound.vb#10)]
## Testing the Application
## Testing the Application
You can now test the form to make sure it behaves as expected.
#### To test the form
### To test the form
- Press F5 to run the application.
You will see a <xref:System.Windows.Forms.DataGridView> control that displays the songs listed in `PopulateDataGridView`. You can add new rows with the **Add Row** button, and you can delete selected rows with the **Delete Row** button. The unbound <xref:System.Windows.Forms.DataGridView> control is the data store, and its data is independent of any external source, such as a <xref:System.Data.DataSet> or an array.
## Next Steps
## Next Steps
This application gives you a basic understanding of the <xref:System.Windows.Forms.DataGridView> control's capabilities. You can customize the appearance and behavior of the <xref:System.Windows.Forms.DataGridView> control in several ways:
- Change border and header styles. For more information, see [How to: Change the Border and Gridline Styles in the Windows Forms DataGridView Control](change-the-border-and-gridline-styles-in-the-datagrid.md).