0

I have a datagridview in MDIChild form, which I ll customize on form load by calling the following function,

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;
    }

but , I am receiving the 'OutOfMemoryException'. When I am removing the above method the application works fine. Why it is happening??

Olivarsham
  • 1,701
  • 5
  • 25
  • 51

1 Answers1

0

Happening that most probabbly the

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

pushed so much data to DataGrid that makes your application explode.

Limit amount of data that you load on the screen, with more "sliced" SQL query.

Tigran
  • 61,654
  • 8
  • 86
  • 123
  • Thanks for ur comment. But, in that select query less than 10 details will come. thats all. what are other possibilites? – Olivarsham Apr 21 '12 at 09:49