C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Tip: This is just one way you can populate a DataGridView. Other approaches are available.
DataRowAdding rows to DataGridView: 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)
{
// Add a column.
this.dataGridView1.Columns.Add("Name", "Text");
// Put all these strings into rows.
string[] input = new string[] { "Alternating", "Row", "Colors", "Are", "Neat" };
foreach (string val in input)
{
this.dataGridView1.Rows.Add(new string[] { val });
}
}
}
}