2012-04-21 89 views
0

我在MDIChild形式,我會通過調用下面的函數形式上載自定義的datagridview,OutOfMemoryException異常在MDIChild

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

發生,這最probabbly

dgvDefCofig.DataSource = dbLayer.tblDefConfigSelectAll().Tables[0]; 

推這麼多的數據來DataGrid,使您的應用程序爆炸。

您在屏幕上加載的數據量有限,更多「切片」SQL查詢。

+0

感謝您的評論。但是,在選擇查詢少於10個細節會來。就這樣。其他可能性是什麼? – Olivarsham 2012-04-21 09:49:38

相關問題