错误无法创建窗口句柄 [英] Error cannot create a window handle

查看:194
本文介绍了错误无法创建窗口句柄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,



我的申请有问题。应用程序有一个Form包含一个数据网格视图,用于显示项目数据。在此类列上按F3时,自定义控件类型的数据网格视图中有一列,它显示另一个用于搜索项目的表单。另一个Form包含另一个数据网格视图,其属性 VirtualMode 设置为true,每个 NewRowNeeded 事件,行数为50.每次我向下滚动50行另外50行被添加到数据网格视图中,依此类推。当我开始用项目填写主要表单数据网格视图时,通过在项目添加一段时间后搜索每一行的项目,我得到无法创建窗口句柄异常,并且在查找GDI对象时它们是436和Handles是2175,我不知道如何解决这种情况?



[更新自OP的评论-SA]:



代码看起来像这样:

Greetings,

I have a problem with an application. The application have a Form contains a data grid view for displaying items data. There is a column within the data grid view of custom control type when pressing F3 on such column it shows another Form for searching the items. The other Form containing another data grid view with the property VirtualMode set to true and a NewRowNeeded event each and a row count of 50. each time I scroll down 50 rows another 50 rows are added to the data grid view and so on. When I begin to fill in the main Form data grid view with items by searching for an item for each row after a while on item adding I got the "cannot create a window handle" exception and when looking for the GDI objects they were 436 and the Handles were 2175 and I do not know how to solve such situation?

[Updated from OP's comment —SA]:

The code simply looks like that:

//Within the custom control event Key Down: 
CustomControl_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyChar == Keys.F3)
{
itemBrowser window = new itemBrowser();
itemBrowser.ShowDialog();
}
}
 
//The code within the itemBrowser within the event that called when scroll down the //data grid view in the item browser window looks like that for example:

dataGridView_NewRowNeeded(object sender, DataGridViewCellValueEventArgs e)
{
if (e.RowIndex == dataGridViewDataSource.Rows.Count - 1)
{
// code here is doing the following
// 1- execute a sql statement to get another 50 items and fill a data table with the // result
// 2- use a for statement to add the resulted table row by row to the //dataGridViewDataSource
}
}

推荐答案

你创建的每个控件都有一个句柄。

我的猜测是你的程序不断添加新的行 - 每个都有一个新的句柄,直到Windows达到一个限制。

可以使DataGridView一次只能保存最多50条记录,并修改或创建新的SQL查询,以便只获取一次需要显示的行。
Each control that you create has a handle.
My guess is that your program keeps adding new rows- one new handle each until Windows reaches a limit.
The DataGridView could be made to only hold max 50 records at a time and modify or create new SQL query to get only rows you need to display at one time.


这篇关于错误无法创建窗口句柄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆