太多的表单实例...... [英] too many form instances...

查看:54
本文介绍了太多的表单实例......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个主表格,显示个人信息(姓名,地址等)绑定

到数据集。

之一信息是该人所属的集团。这是从组合框中选择的


如果我想在列表中添加新组。我打开一个这样的新表格


myfrmAddGroup = New FrmAddGroup(Me.Dataset1)

myfrmAddGroup.Show()

myfrmAddGroup =没有什么


FrmAddgroup有这个构造函数:


Public Sub New(ByRef inpds As Dataset)


然后它使用这个数据集作为网格中的数据源。

到目前为止没有问题。


但是如果我打开表单并添加一个新组。

然后关闭表单

然后打开表单并删除一个组。 (任何组)

我收到错误:

"'System.IndexOutOfRangeException'类型未处理的异常发生

在系统中.windows.forms.dll

附加信息:索引13没有值。"

在_main_表格第一行(公共类frmMainForm)。

我无法调试它。它没有说它出现在哪里。 (我当然是

试试所有功能)


(我在组列表中有14项)

我向frmAddGroup添加了一个rowdeleting事件处理程序,看起来每次打开表单时都会调用一次这个

。即如果打开并关闭

表单5次,当我删除一行时,eventhandler被调用5次。


所以它是有道理的:它首先删除了按行应该排。指数13

没问题。但随后它又尝试删除索引13处的行。并失败。

如何摆脱frmAddGroup的封闭实例,这样就不会发生
了?


任何建议?


TIA


Jan

Hi
I have a main form showing personal information (name, address etc.) bound
to a dataset.
One of the pieces of information is the Group the person belongs to. This is
selected from a combo box.
If I want to add a new group to the list. I open a new form like this

myfrmAddGroup = New FrmAddGroup(Me.Dataset1)
myfrmAddGroup.Show()
myfrmAddGroup = Nothing

The FrmAddgroup has this constructor:

Public Sub New(ByRef inpds As Dataset)

It then uses this dataset as datasource in a grid.
No problems this far.

But if I open the form and add a new group.
Then close the form
Then open the form and delete a group. (Any group)
I receive the error:
"An unhandled exception of type ''System.IndexOutOfRangeException'' occurred
in system.windows.forms.dll
Additional information: No value at index 13."
In the _main_ forms first line (Public Class frmMainForm) .
And I can′t debug it. It does not say where it appeared. (And I of course
have try catch on all functions)

(I have 14 items in the group list)
I added an rowdeleting eventhandler to frmAddGroup and it appears that this
is called one time for each time I open the form. Ie if open and close the
form 5 times the eventhandler is called 5 times when I delete a row.

So it makes sense: it first deletes the row as it is supposed to. index 13
is fine. But then it tries to delete the row at index 13 again. and fails.
How do get rid of the closed instances of the frmAddGroup so this will not
happen?

Any suggestions?

TIA

Jan

推荐答案

Jan,

Jan,

新的FrmAddGroup(Me.Dataset1)
myfrmAddGroup.Show()
myfrmAddGroup = Nothing
New FrmAddGroup(Me.Dataset1)
myfrmAddGroup.Show()
myfrmAddGroup = Nothing



当我看到这种代码时,我直接想到IsDisposed


将frm设置为空,没有任何意义,顺便说一下,当

仍有对该对象的引用。

http://msdn.microsoft.com/library/de...posedtopic.asp


来自Hefried的消息中的一段代码

\\\\

如果foSear chForm什么都没有orElse foSearchForm.IsDisposed然后

foSearchForm =新的FrmSearchForm()

结束如果

foSearchForm.Show()

///


我希望这有帮助吗?


Cor



When I see this kind of code I think directly on "IsDisposed"

Setting a frm to nothing has no sense by the way, this will be ignored when
there is still a reference to that object.

http://msdn.microsoft.com/library/de...posedtopic.asp

A piece of code from a message from Hefried
\\\\
If foSearchForm Is Nothing OrElse foSearchForm.IsDisposed Then
foSearchForm = New FrmSearchForm()
End If
foSearchForm.Show()
///

I hope this helps?

Cor


Jan,

Jan,

新的FrmAddGroup(Me.Dataset1)
myfrmAddGroup.Show()
myfrmAddGroup = Nothing
New FrmAddGroup(Me.Dataset1)
myfrmAddGroup.Show()
myfrmAddGroup = Nothing




当我看到这种代码时,我直接想到IsDisposed


设置一个frm到没什么没有意义的方式当

仍有对该对象的引用时,这将被忽略。

http://msdn.microsoft.com/library/de...posedtopic.asp


来自Hefried的消息中的一段代码

\\\\

如果foSearchForm没什么,那么foSearchForm.IsDisposed那么

foSearchForm =新的FrmSearchForm()

结束如果

foSearchForm.Show()< br $>
///


我希望这有帮助吗?


Cor



When I see this kind of code I think directly on "IsDisposed"

Setting a frm to nothing has no sense by the way, this will be ignored when
there is still a reference to that object.

http://msdn.microsoft.com/library/de...posedtopic.asp

A piece of code from a message from Hefried
\\\\
If foSearchForm Is Nothing OrElse foSearchForm.IsDisposed Then
foSearchForm = New FrmSearchForm()
End If
foSearchForm.Show()
///

I hope this helps?

Cor


Hi Cor

感谢您的回答。


我试过Herfrieds代码

它没有有所不同。

记住我关闭表格(点击红色X)然后打开它,然后关闭

等等

这个也处理它。 (我已经证实了这一点。表格的处理是

执行)


Jan

" Cor Ligthert" <无************ @ planet.nl> skrev i en meddelelse

news:e%**************** @ TK2MSFTNGP14.phx.gbl ...
Hi Cor
Thanks for answering.

I tried Herfrieds code
It does not make any difference.
Remember I close the form (by clicking the red X) then open it, then close
it etc.
This also disposes it. (I have verified this. The Dispose of the form is
executed)

Jan
"Cor Ligthert" <no************@planet.nl> skrev i en meddelelse
news:e%****************@TK2MSFTNGP14.phx.gbl...
Jan ,

Jan,

新的FrmAddGroup(Me.Dataset1)
myfrmAddGroup.Show()
myfrmAddGroup = Nothing
New FrmAddGroup(Me.Dataset1)
myfrmAddGroup.Show()
myfrmAddGroup = Nothing



当我看到这种代码时,我直接想到IsDisposed

设置一个frm到没有任何东西没有任何意义的方式,这将被忽略
当仍然有引用该对象。

http://msdn.microsoft.com/library/de...posedtopic.asp

来自邮件的一段代码来自Hefried
\\\\
如果foSearchForm什么也没有,那么foSearchForm.IsDisposed那么
foSearchForm =新的FrmSearchForm()
结束如果
foSearchForm.Show ()
///

我希望这会有所帮助?



When I see this kind of code I think directly on "IsDisposed"

Setting a frm to nothing has no sense by the way, this will be ignored
when there is still a reference to that object.

http://msdn.microsoft.com/library/de...posedtopic.asp

A piece of code from a message from Hefried
\\\\
If foSearchForm Is Nothing OrElse foSearchForm.IsDisposed Then
foSearchForm = New FrmSearchForm()
End If
foSearchForm.Show()
///

I hope this helps?

Cor



这篇关于太多的表单实例......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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