One feature of the DataGridView control in Windows Forms is the ability for users to add new rows and data to your form. Then, you can use C# code in an event handler such as RowEnter to read in the data that was added. We show how a user can add data to a custom column and then how this data can be used.

This C# article uses the RowEnter event handler to add new rows to DataGridView.
First, the above screenshot shows a DataGridView control where several rows were added. In the DataGridView, one column exists. This was added in the Form1_Load event handler below. When the Enter key is pressed, the data put inside each row is read and printed to the Text property of the Form.
This code sample demonstrates how you can use the Load event on the form and the RowEnter event on the DataGridView. To create the Load event handler, double-click on the window containing your DataGridView. To create the RowEnter event handler, select the DataGridView and select Properties > Events and then RowEnter. This event will trigger every time the user presses Enter.
Code that uses RowEnter event handler [C#]
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// Create one column.
this.dataGridView1.Columns.Add("Text", "Text");
}
private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
{
// Get all rows entered on each press of Enter.
var collection = this.dataGridView1.Rows;
string output = "";
foreach (DataGridViewRow row in collection)
{
foreach (DataGridViewCell cell in row.Cells)
{
if (cell.Value != null)
{
output += cell.Value.ToString() + " ";
}
}
}
// Display.
this.Text = output;
}
}
}Accessing data. There are many ways to access the data input in a DataGridView. In dataGridView1_RowEnter, we access the Rows property, and then loop over all the rows and then the cells. We create a string and then change the Form Text property to be equal to that string.

You can also add rows to your DataGridView using C# code. This is demonstrated in the core article on the DataGridView control on this site.
DataGridView TipsThe DataGridView control is not just a way to display data from a database; you can use it to have users enter data. This article demonstrated one way you can access new data as it is put into your program. With the data in your program's object model, you can then persist it, validate it, or flag it with errors.
Windows Forms