System.OutOfMemoryException was thrown when SaveAs c1flexgrid to Excel file

Posted by: levanduyet on 21 December 2023, 11:13 pm EST

    • Post Options:
    • Link

    Posted 21 December 2023, 11:13 pm EST

    Hi,

    I have extracted the data to the c1flexgrid, when I save to Excel file, it was thrown System.OutOfMemoryException error.

    My code is as following:

    if (flexgridDelivery.Rows.Count == 1)
    {
    	MessageBox.Show("There isn't data.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
    	return;
    }
    
    SaveFileDialog dlg = new SaveFileDialog();
    dlg.Filter = "XLSX|*.xlsx|XLS|*.xls";
    dlg.Title = "Save as Excel file";
    dlg.DefaultExt = "xlsx";
    dlg.FilterIndex = 1;
    dlg.RestoreDirectory = true;
    dlg.ShowDialog();
    
    if (dlg.FileName != "")
    {
    	flexgridDelivery.SaveExcel(dlg.FileName, FileFlags.AsDisplayed | FileFlags.IncludeFixedCells);
    	MessageBox.Show("You have saved with the name " + dlg.FileName, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }

    So, What should I do to settle this issue.

    Thanks,

    Duyet Le

  • Posted 22 December 2023, 5:38 am EST

    Hi Duyet,

    since in the past I had a similar (now solved) issue, can U provide the full sample, including how u fill the grid?

    Otherwise would be impossibile to try to reproduce by me and by Mescius itself!

  • Posted 22 December 2023, 1:41 pm EST

    Hi fabio,

    I fill the grid as normal. I work well. Just when I export with big data on the grid then I have a problem.

    private void btnSummaryByCustomer_Click(object sender, EventArgs e)
    {
    	this.Cursor = Cursors.WaitCursor;
    	try
    	{
    		DateTime dFromDate = (DateTime)txtFromDate.Value;
    		DateTime dToDate = (DateTime)txtToDate.Value;
    		List<string> itemBoKhongBom = new List<string>();//Nhằm lưu mã bộ không có BOM, nếu không có BOM sẽ không xóa
    		int result = DateTime.Compare(dFromDate, dToDate);
    		if (result > 0)
    		{
    			MessageBox.Show("Pls check the date.", "information", MessageBoxButtons.OK, MessageBoxIcon.Information);
    			return;
    		}
    		else
    		{
    			if (dFromDate.AddDays(31) <= dToDate)
    			{
    				MessageBox.Show("The period is only 1 month. Pls enter again.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
    				txtFromDate.Focus();
    				return;
    			}
    			if (string.IsNullOrEmpty(txtWarehouse.Text))
    			{
    				MessageBox.Show("Pls enter the warehouse code.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
    				txtWarehouse.Focus();
    				return;
    			}
    			//Get Exchange rate
    			string sExchangeRate = txtExchangeRate.Text.Trim();
    			double dExchangeRate = 1;
    			if (!double.TryParse(sExchangeRate, out dExchangeRate))
    			{
    				MessageBox.Show("Pls check the exchange rate.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
    				return;
    			}
    			string wareHouse = txtWarehouse.Text;
    			//Nếu ngày nhập vào okay thì bắt đầu kiểm tra dữ liệu
    			ExactDB objGiaoHang = new ExactDB();
    			//Neu ton tai moi thuc hien
    			DataTable dtResult = new DataTable();
    
    			//Kho nệm: '301 '
    			dtResult = objGiaoHang.GetDnByWarehouseFromTo_Update(wareHouse, dFromDate, dToDate); //Lấy số lượng giao hàng từ ngày đến ngày
    			if (dtResult == null || dtResult.Rows.Count == 0)
    			{
    				MessageBox.Show("There is no any document match with your request.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
    			}
    			else
    			{
    				#region Export data to flexgrid
    				fgGiaoHang.BeginUpdate();
    				this.iniFlexgridKhachHang(1);
    				int hangBatDau = 1;
    
    				foreach (DataRow dtRow in dtResult.Rows)
    				{
    					string sIbtDoc = dtRow["IbtDoc"] != null ? dtRow["IbtDoc"].ToString() : "";
    					if (string.IsNullOrEmpty(sIbtDoc))
    					{
    						fgGiaoHang.Rows.Add();
    						hangBatDau = fgGiaoHang.Rows.Count - 1;
    						fgGiaoHang[hangBatDau, 3] = dtRow["DocDate"]; //.ToString();
    						fgGiaoHang[hangBatDau, 1] = dtRow["DebCode"];
    						string tenKH = dtRow["DebName"].ToString();
    						tenKH = AllLib.StringExtension.VNItoUNICODE(tenKH);
    						fgGiaoHang[hangBatDau, 2] = tenKH;
    						fgGiaoHang[hangBatDau, 4] = dtRow["DnNumber"];
    
    						fgGiaoHang[hangBatDau, 5] = dtRow["ItemCode"];
    						string sProductName = dtRow["Description"].ToString();
    						sProductName = AllLib.StringExtension.VNItoUNICODE(sProductName);
    						fgGiaoHang[hangBatDau, 6] = sProductName;
    						string sDvt = dtRow["Unitcode"].ToString();
    						sDvt = AllLib.StringExtension.VNItoUNICODE(sDvt);
    						fgGiaoHang[hangBatDau, 7] = sDvt;
    						string sQtyIn = dtRow["QtyIn"].ToString();
    						string sQtyOut = dtRow["QtyOut"].ToString();
    						double dQtyIn = 0;
    						if (!double.TryParse(sQtyIn, out dQtyIn))
    						{
    							dQtyIn = 0;
    						}
    						double dQtyOut = 0;
    						if (!double.TryParse(sQtyOut, out dQtyOut))
    						{
    							dQtyOut = 0;
    						}
    						fgGiaoHang[hangBatDau, 8] = dQtyOut - dQtyIn;
    
    						string ghiChu = dtRow["Remark"] != null ? dtRow["Remark"].ToString() : "";
    						ghiChu = AllLib.StringExtension.VNItoUNICODE(ghiChu);
    						fgGiaoHang[hangBatDau, 9] = ghiChu;
    						fgGiaoHang[hangBatDau, 10] = dtRow["OrderNo"];
    						fgGiaoHang[hangBatDau, 11] = dtRow["DnNumberOnPXK"];
    
    						fgGiaoHang[hangBatDau, 12] = dtRow["InvNo"];
    						fgGiaoHang[hangBatDau, 13] = dtRow["VATPercent"];
    
    						fgGiaoHang[hangBatDau, 14] = dtRow["AmountWithoutVAT"];
    						fgGiaoHang[hangBatDau, 15] = dtRow["AmountWithVAT"];
    
    
    					}
    				}
    
    
    				fgGiaoHang.Cols[14].Format = "#,##0.00";    // thousands 
    				fgGiaoHang.Cols[15].Format = "#,##0.00";    // thousands 
    				fgGiaoHang.Cols[3].Format = "dd/MM/yyyy";   // Re-format the date column
    
    				#endregion
    
    				#region Arrange and Total
    				//Sắp xếp
    				//Apply sorting on multiple columns
    				fgGiaoHang.Cols[1].Sort = SortFlags.Ascending;//Ma khach hang
    				fgGiaoHang.Cols[4].Sort = SortFlags.Ascending;//So DN
    															  //Call the Sort method
    				fgGiaoHang.Sort(SortFlags.UseColSort, 1, 4);
    			   
    				//Sắp xếp: note không cần sắp xếp vì khi lấy dữ liệu ra đã sắp xếp theo Ngày và Mã khách hàng
    				//Thiết lập SubTotal
    				fgGiaoHang.Tree.Column = 0;//Nút subtotal ở cột ngoài cùng
    				fgGiaoHang.Tree.Style = TreeStyleFlags.Simple;
    				//Xoá subtotal hiện tại
    				fgGiaoHang.Subtotal(AggregateEnum.Clear);
    				//Total dựa trên Ngày tính ở cột số lượng
    				fgGiaoHang.Subtotal(AggregateEnum.Sum, 1, 1, 8, "{0}");//So luong
    				fgGiaoHang.Subtotal(AggregateEnum.Sum, 1, 1, 14, "{0}");//Tong chua VAT
    				fgGiaoHang.Subtotal(AggregateEnum.Sum, 1, 1, 15, "{0}");//Tong co VAT
    				//Thêm Grand total
    				fgGiaoHang.Subtotal(AggregateEnum.Sum, -1, -1, 8, "Tổng tất cả");
    				fgGiaoHang.Subtotal(AggregateEnum.Sum, -1, -1, 14, "Tổng tất cả");
    				fgGiaoHang.Subtotal(AggregateEnum.Sum, -1, -1, 15, "Tổng tất cả");
    				fgGiaoHang.Cols[0].Width = 100;
    				fgGiaoHang.Tree.Show(1);
    				#endregion
    				#region Fill some more information at the node line
    				for (int j = 1; j < fgGiaoHang.Rows.Count; j++)
    				{
    					if (fgGiaoHang.Rows[j].IsNode == true && fgGiaoHang.Rows[j].Node.Level == 1)
    					{
    						fgGiaoHang[j, 1] = fgGiaoHang[j + 1, 1];//Mã khách hàng
    						fgGiaoHang[j, 2] = fgGiaoHang[j + 1, 2];//Tên khách hàng
    					}
    				}
    
    				#endregion
    			}
    
    		}
    
    	}
    	catch (Exception ex)
    	{
    		if (ex.Message.IndexOf("Exception has been thrown by the target of an invocation") >= 0)
    		{
    
    			MessageBox.Show("It took to long or you don't have a right to access.\nPls contact your admin.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
    		}
    		else
    		{
    			MessageBox.Show("The error is \n" + ex.Message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
    		}
    	}
    	finally
    	{
    		fgGiaoHang.EndUpdate();
    		//reset cursor
    		this.Cursor = Cursors.Default;
    	}
    }

    Thanks,

    Duyet Le

  • Posted 25 December 2023, 11:12 pm EST

    Hello Duyet Le,

    Thank you for bringing this matter to our attention.

    This is a known issue, and it has already been reported to the dev team. We will give you an update as soon as this issue is fixed.

    Thank you for your understanding and cooperation.

    Internal tracking ID: C1WIN-31497

    Regards,

    Uttkarsh.

  • Posted 4 January 2024, 3:14 am EST

    Hi Uttkarsh,

    When this one can be fixed. I use 4.5.2 version.

    Thanks,

    Duyet Le

  • Posted 4 January 2024, 9:49 pm EST

    Hello Duyet Le,

    As per the developers, the issue has been fixed internally and will be available in 2023 v3 hotfix 1 builds. It is expected to be released in the upcoming week.

    regards,

    Uttkarsh.

  • Posted 4 January 2024, 11:56 pm EST

    Dear Uttkarsh,

    Tks,

    I need that.

    Duyet Le

  • Posted 22 January 2024, 11:00 pm EST

    Hello,

    Any news.

    Tks,

    Duyet Le

  • Posted 23 January 2024, 11:25 pm EST

    Hello Duyet Le,

    These issues are fixed in the latest 2023v2 HF (636) release. This release is currently available for installation from NuGet and will be available for update from ComponentOneControlPanel in a few days.

    Nuget: https://www.nuget.org/packages/C1.Win.FlexGrid/8.0.20233.636

    Please confirm if the issue is fixed in the latest version. If the issue is still replicable, could you please provide a stripped-down sample replicating the behavior so that we can investigate it on our end too?

    Regards,

    Uttkarsh.

  • Posted 28 January 2024, 12:06 am EST

    Hi Uttkarsh,

    My project is 4.5.2 but this update not for version 4.5.2

    Do I have any way to update for 4.5.2.

    Thanks,

    Duyet LE

  • Posted 28 January 2024, 12:08 am EST - Updated 28 January 2024, 12:13 am EST

  • Posted 28 January 2024, 9:06 pm EST

    Hi Duyet,

    it is probably https://www.nuget.org/packages/C1.Win.C1FlexGrid/4.8.20233.636 - but C1 discontinued the 4.5 framework support and now only supports 4.8, as far as I understand, so you would have to upgrade to .NET framework 4.8.

    Best regards

    Wolfgang

  • Posted 28 January 2024, 9:47 pm EST

    Hello Duyet Le,

    Thank you, Wolfgang, for the comment.

    Microsoft ended its support for .NET Framework 4.5.2 on April 26, 2022 [https://learn.microsoft.com/en-us/lifecycle/products/microsoft-net-framework]. Consequently, our 4.5.2 controls are now in maintenance mode, meaning no further updates will be introduced for this version.

    Please, if possible, migrate your project to .NET 4.6.2/4.8 and then download the latest nuget version of C1FlexGrid, 2023v2 HF (636) to resolve the issue. To see how to migrate to the latest FW controls, please see the following blog post: https://developer.mescius.com/blogs/how-to-migrate-to-net-framework-4-8-using-componentone

    Nuget download link: https://www.nuget.org/packages/C1.Win.C1FlexGrid/4.8.20233.636

    ComponentOne ControlPanel: Products → Build Repository → (check “Include prerelease and hotfix versions” checkbox.) → Winforms → Update .NET 4.6.2 (please refer to the attached image, Update.zip)

    Regards,

    Uttkarsh.

  • Posted 29 January 2024, 11:16 pm EST - Updated 29 January 2024, 11:21 pm EST

    Hi Uttkarsh,

    Same as last times, I have upgrade follow the process, rebuild, I run it okay but I could not open form in design mode. The error show as following:

    I don’t know why.

    Duyet Le

  • Posted 30 January 2024, 12:14 am EST - Updated 30 January 2024, 12:19 am EST

  • Posted 30 January 2024, 12:56 am EST - Updated 30 January 2024, 1:02 am EST

  • Posted 30 January 2024, 1:01 am EST - Updated 30 January 2024, 1:16 am EST

    I found out that, the error is as following:

    // 
                // rbb01
                // 
                this.rbb01.IconSet.Add(new C1.Framework.C1BitmapIcon("ChartBar", new System.Drawing.Size(20, 20), System.Drawing.Color.Transparent, "Preset_MediumImages", 64));
                this.rbb01.Name = "rbb01";
                this.rbb01.Text = "Test01";
                // 
                // rbb02
                // 
                this.rbb02.IconSet.Add(new C1.Framework.C1BitmapIcon("BringForward", new System.Drawing.Size(20, 20), System.Drawing.Color.Transparent, "Preset_MediumImages", 43));
                this.rbb02.Name = "rbb02";
                this.rbb02.Text = "Test02";

    When I block the code line

    this.rbb01.IconSet.Add(new C1.Framework.C1BitmapIcon("ChartBar", new System.Drawing.Size(20, 20), System.Drawing.Color.Transparent, "Preset_MediumImages", 64));

    And

    this.rbb02.IconSet.Add(new C1.Framework.C1BitmapIcon("BringForward", new System.Drawing.Size(20, 20), System.Drawing.Color.Transparent, "Preset_MediumImages", 43));

    Then I could open form in design mode.

    Duyet Le

  • Posted 30 January 2024, 11:10 pm EST

    Hello Duyet Le,

    Apologies, but we could not replicate any of the errors mentioned above on our end.

    We created a .Net 4.5.2 application with a Ribbon and FlexGrid (4.5.20232.620 build of C1Controls), then we tried to migrate it to .Net 4.8 and 4.8.20233.636, the latest build of C1Controls. We did not encounter any of the mentioned issues during the process.

    Steps we followed on our end:

    1. created a .Net 4.5.2 application with a Ribbon and FlexGrid (4.5.20232.620 build of C1Controls). Please refer to the attached sample, WindowsFormsApp_452.zip.
    2. Removed .Net 4.5.2 DLLs of C1Controls. (refer “Removing 452 DLLs.png” in Steps.zip)
    3. Added .Net 4.8 DLLs of C1Controls. (refer “Adding 48 DLLs.png” in Steps.zip)
    4. Updated the licx file. (refer “Old licx file.png” and “Updated licx file.png” in Steps.zip)

    Also refer to the attached migrated sample, WindowsFormsApp_48.zip.

    Are you doing anything that is different from the above-mentioned steps? If yes, could you please provide us the steps so that we could try to replicate the behavior?

    Regards,

    Uttkarsh.

    Steps.zip

  • Posted 30 January 2024, 11:59 pm EST

    Hi Uttkarsh,

    _ I have un-install, and reinstall again + add hot fix file to the location:

    C:\Program Files (x86)\ComponentOne\WinForms Edition\bin\v4.8

    _ After that I re-reference all the files, then it’s okay now.

    Thanks,

    Duyet Le

  • Posted 31 January 2024, 3:12 pm EST

    Hello Duyet Le,

    Thank you for updating us on the steps you took to address the issue. We are glad to hear that your issue has been resolved.

    If you encounter any further challenges or have additional questions, please don’t hesitate to reach out to us.

    Regards,

    Uttkarsh

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels