WinForm is unlike ASP.NET (Web Application). ASP.NET is sending data through internet connection. There is a performance issue if you are sending large data to client's web browser.
But in WinForm development, the data is transmitting within the memory of computer. Hundred thousands of rows is sent and received almost instantly. You can load Hundred Thousands of rows at once at DataGridView. No problem.
You just need to implement VirtualMode of DataGridView control.
By enabling VirtualMode = true, DataGridView is not holding any actual data.
The data is retrieved from other source such as DataTable, List<object>, etc.
Therefore, the DataGridView will consume very little of memory.
Here is some of the basic intro about VirtualMode. For more details, you may Google it.
(Note: Code Tested)
public partial class Form1 : Form
{
Random rd = new Random();
DataTable dt = new DataTable();
public Form1()
{
InitializeComponent();
CreateSampleData();
DataGridView dataGridView1 = new DataGridView();
this.Controls.Add(dataGridView1);
dataGridView1.Dock = DockStyle.Fill;
dataGridView1.VirtualMode = true;
dataGridView1.CellValueNeeded += dataGridView1_CellValueNeeded;
dataGridView1.DataSource = dt;
}
void dataGridView1_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e)
{
if (e.RowIndex >= dt.Rows.Count)
return;
if (e.ColumnIndex >= dt.Columns.Count)
return;
e.Value = dt.Rows[e.RowIndex][e.ColumnIndex];
}
void CreateSampleData()
{
dt.Columns.Add("col1");
dt.Columns.Add("col2");
dt.Columns.Add("col3");
dt.Columns.Add("col4");
dt.Columns.Add("col5");
Random rd = new Random();
for (int i = 0; i < 1000000; i++)
{
dt.Rows.Add(GetRandomData());
}
}
private string[] GetRandomData()
{
string[] sa = new string[5];
for (int i = 0; i < sa.Length; i++)
{
sa[i] = rd.Next(0, int.MaxValue).ToString();
}
return sa;
}
}