I am using System.Windows.Forms.DataGrid. It is filled with approximately 3,000 rows and redraws very slowly. If I minimize and maximize my form, all the other controls just display, but in the end I look at the DataGrid redrawing row by row. Everything in this DataGrid is read-only, if that matters.
Update:
I'm not sure how to properly implement the CellValueNeeded () event for my project, or if this will help the DataGrid performance in my case.
I am creating a User Control that contains a DataGridView (see code below). When the SetProject () method is called, my control is set to a specific instance of my Project class. The control then uses the static method Informa.Data.GetProjectDataTable (Project proj) to retrieve the DataTable from the project. Then, the DataSource DataGrid property is set to the returned DataTable.
This is the first time I have done anything with ADO or DataGrids, so bear with me. It seems that CellValueNeed () allows me to override how the DataGrid finds a value for one of its cells, but in my case it is much more complicated than the examples on MSDN. The actual source of my data is the tree structure of various Node objects, the root of which is the project instance. Each Node can have a variable set of properties, which can also be extended by the user at runtime. Then there are many other difficulties with Nodes inheriting property values from their parent nodes, and summing other properties from their child nodes.
Informa.Data.GetProjectDataTable() DataTable . . , , DataGrid.
, CellValueNeeded() DataTable, ? , DataGrid , DataTable ?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Informa;
namespace Informa
{
public partial class ProjectGridControl : UserControl
{
private Project proj;
public ProjectGridControl()
{
InitializeComponent();
}
public void SetProject(Project proj)
{
this.proj = proj;
UpdateGridControl();
}
public void UpdateGridControl()
{
if (this.proj == null)
{
this.dataGrid.DataSource = null;
}
else
{
this.dataGrid.DataSource = Informa.Data.GetProjectDataTable(proj);
}
}
}
}