我有一个MDIChild形式的datagridview,我将通过调用以下函数来自定义表单加载,
private void FillDetails()
{
dgvDefCofig.DataSource = dbLayer.tblDefConfigSelectAll().Tables[0];
var columnheaderstyle = new DataGridViewCellStyle();
columnheaderstyle.Font = new Font("Arial", 9, FontStyle.Regular);
dgvDefCofig.ColumnHeadersDefaultCellStyle = columnheaderstyle;
dgvDefCofig.Columns[dgvDefCofig.Columns.Count - 1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
SetLineColumnDetails("ID", "", 0, DataGridViewContentAlignment.MiddleLeft, false);
SetLineColumnDetails("DC_NoOfSmallBoxes", "No of Boxes", 50, DataGridViewContentAlignment.MiddleLeft, true);
SetLineColumnDetails("DC_LabelPath", "Label path", 250, DataGridViewContentAlignment.MiddleLeft, true);
SetLineColumnDetails("DC_Active", "Active", 100, DataGridViewContentAlignment.MiddleRight, true);
SetLineColumnDetails("DC_InsertedDateTime", "Inserted Date", 100, DataGridViewContentAlignment.MiddleRight, true);
SetLineColumnDetails("DC_ProdDate", "Producation Date", 100, DataGridViewContentAlignment.MiddleRight, true);
SetLineColumnDetails("DC_ProdShift", "Shift", 0, DataGridViewContentAlignment.MiddleRight, false);
SetLineColumnDetails("DC_CreatedBy", "Created By", 0, DataGridViewContentAlignment.MiddleRight, false);
SetLineColumnDetails("DC_LastUpdateDate", "Last Updated", 0, DataGridViewContentAlignment.MiddleRight, false);
SetLineColumnDetails("DC_LastUpdatedBy", "Lase Updated By", 100, DataGridViewContentAlignment.MiddleRight, true);
}
public void SetLineColumnDetails(string columnName, string headertext, int width,
DataGridViewContentAlignment alignment, bool visible)
{
dgvDefCofig.Columns[columnName].Visible = visible;
dgvDefCofig.Columns[columnName].HeaderText = headertext;
dgvDefCofig.Columns[columnName].Width = width;
dgvDefCofig.Columns[columnName].DefaultCellStyle.Alignment = alignment;
}
但是,我收到'OutOfMemoryException'。当我删除上述方法时,应用程序工作正常。 它为什么会发生?
答案 0 :(得分:0)
发生最可能
dgvDefCofig.DataSource = dbLayer.tblDefConfigSelectAll().Tables[0];
将大量数据推送到DataGrid
,导致您的应用程序爆炸。
限制您在屏幕上加载的数据量,并使用更多“切片”SQL
查询。