我有一个winform窗口,在显示少量数据的时候完全正常,但显示大量数据(四五千条记录左右)就出现问题,说程序遇到问题需要关闭,由此给你带来不便表示抱歉。我通过调试获取了报错的详细信息,现贴出来求高手帮我看看及解悉一下,有什么解决办法。谢谢。---------------------------------报错信息-------------------------------
未处理 System.ComponentModel.Win32Exception
Message="创建窗口句柄时出错。"
Source="System.Windows.Forms"
ErrorCode=-2147467259
NativeErrorCode=1158
StackTrace:
在 System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
在 System.Windows.Forms.Control.CreateHandle()
在 System.Windows.Forms.Control.get_Handle()
在 System.Windows.Forms.Control.CreateGraphicsInternal()
在 System.Windows.Forms.ThreadExceptionDialog..ctor(Exception t)
在 System.Windows.Forms.Application.ThreadContext.OnThreadException(Exception t)
在 System.Windows.Forms.Control.WndProcException(Exception e)
在 System.Windows.Forms.Control.ControlNativeWindow.OnThreadException(Exception e)
在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(Form mainForm)
InnerException:
未处理 System.ComponentModel.Win32Exception
Message="创建窗口句柄时出错。"
Source="System.Windows.Forms"
ErrorCode=-2147467259
NativeErrorCode=1158
StackTrace:
在 System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
在 System.Windows.Forms.Control.CreateHandle()
在 System.Windows.Forms.Control.get_Handle()
在 System.Windows.Forms.Control.CreateGraphicsInternal()
在 System.Windows.Forms.ThreadExceptionDialog..ctor(Exception t)
在 System.Windows.Forms.Application.ThreadContext.OnThreadException(Exception t)
在 System.Windows.Forms.Control.WndProcException(Exception e)
在 System.Windows.Forms.Control.ControlNativeWindow.OnThreadException(Exception e)
在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(Form mainForm)
InnerException:
右键“我的电脑”--管理--服务和应用程序--服务--右边窗口找到“terminal services”并用鼠标双击,在弹出的窗口中,启动类型选择“自动”,服务状态 点击“启动”按钮,点击“应用”按钮,确定退出,重启电脑即可。
在IIS6.0中,默认设置是特别严格和安全的,最大只能传送204,800个字节
private void ShowTextBoxList(List<BillDetails> bdList)
{
panBillTextBox.Controls.Clear();//panBillTextBox是窗体上的Panel
if (bdList.Count > 0)
{
lbEmpty.Visible = false; //隐藏无数据时的提示Label
Point point = new Point(0, 0);
for (int i = 0; i < bdList.Count; i++)
{
BillDetails bd = bdList[i];
//BillDetailsTextBox是一个用户控件,用于把一个明细项显示出来
BillDetailsTextBox bdtb = new BillDetailsTextBox(bd.ProName, bd.PayMoney, bd.Qty, bd.Unit, bd.Re);
bdtb.Location = point;
bdtb.OnPayMoneyChange += new BillDetailsTextBox.PayMoneyChangeHandle(bdtb_OnPayMoneyChange);
panBillTextBox.Controls.Add(bdtb);
//以下用于控制将各明细项在窗口分三列显示
if ((i + 1) % 3 == 0)
{
point.X = 0;
point.Y = point.Y + bdtb.Height + rowSpan;
}
else
{
point.X = point.X + colSpan + bdtb.Width;
if (i == bdList.Count - 1)
point.Y = point.Y + bdtb.Height + rowSpan;//最后总长度一定要加上,否则不能显示最后一行。
}
}
this.Height = point.Y;
}
else
{
//如果无数据,显示无数据时的提示Label
lbEmpty.Visible = true;
}
}
请问像这种情况最好怎样做处理?
16楼可能是个办法,但画个滚动条的确有点费劲。我试过如果用DataGridView绑定10000+条记录也可以完全正常工作,谁能说说当中的机制是什么呀?
而你的做法,可以想象成是弄了成千上万个DataGridView,虽然屏幕上没有显示,但是new一个控件是要消耗很多系统资源的
但我认为我们学习的人,就该尝试不同的方法去实现!!!