473,783 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

too many form instances...

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.S how()
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.IndexOu tOfRangeExcepti on' 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
Nov 21 '05 #1
18 1647
Jan,

New FrmAddGroup(Me. Dataset1)
myfrmAddGroup.S how()
myfrmAddGroup = Nothing


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.Is Disposed Then
foSearchForm = New FrmSearchForm()
End If
foSearchForm.Sh ow()
///

I hope this helps?

Cor

Nov 21 '05 #2
Jan,

New FrmAddGroup(Me. Dataset1)
myfrmAddGroup.S how()
myfrmAddGroup = Nothing


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.Is Disposed Then
foSearchForm = New FrmSearchForm()
End If
foSearchForm.Sh ow()
///

I hope this helps?

Cor

Nov 21 '05 #3
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%******** ********@TK2MSF TNGP14.phx.gbl. ..
Jan,

New FrmAddGroup(Me. Dataset1)
myfrmAddGroup.S how()
myfrmAddGroup = Nothing


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.Is Disposed Then
foSearchForm = New FrmSearchForm()
End If
foSearchForm.Sh ow()
///

I hope this helps?

Cor

Nov 21 '05 #4
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%******** ********@TK2MSF TNGP14.phx.gbl. ..
Jan,

New FrmAddGroup(Me. Dataset1)
myfrmAddGroup.S how()
myfrmAddGroup = Nothing


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.Is Disposed Then
foSearchForm = New FrmSearchForm()
End If
foSearchForm.Sh ow()
///

I hope this helps?

Cor

Nov 21 '05 #5
Jan,

A question, is there in your datagrid a comboboxcolumn?

Cor

"Jan Nielsen"
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%******** ********@TK2MSF TNGP14.phx.gbl. ..
Jan,

New FrmAddGroup(Me. Dataset1)
myfrmAddGroup.S how()
myfrmAddGroup = Nothing


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.Is Disposed Then
foSearchForm = New FrmSearchForm()
End If
foSearchForm.Sh ow()
///

I hope this helps?

Cor


Nov 21 '05 #6
Jan,

A question, is there in your datagrid a comboboxcolumn?

Cor

"Jan Nielsen"
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%******** ********@TK2MSF TNGP14.phx.gbl. ..
Jan,

New FrmAddGroup(Me. Dataset1)
myfrmAddGroup.S how()
myfrmAddGroup = Nothing


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.Is Disposed Then
foSearchForm = New FrmSearchForm()
End If
foSearchForm.Sh ow()
///

I hope this helps?

Cor


Nov 21 '05 #7
Jan,

I do not understand this.
Therefore I added a sample is that something as you are doing this?

\\\form1 with a button
Dim ds As New DataSet
Dim frm As Form2
Private Sub Form1_Load(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
createDS()
frm = New Form2(ds)
frm.Owner = Me
frm.Show()
End Sub
Private Sub Button1_Click(B yVal sender As System.Object, _
ByVal e As System.EventArg s) Handles Button1.Click
ds.Tables(0).Ro ws(2).Delete()
If frm.IsDisposed Then
frm = New Form12(ds)
frm.Show()
Else
frm.TopMost = True
End If
End Sub
Public Sub createDS()
Dim dt As New DataTable
ds.Tables.Add(d t)
dt.Columns.Add( "Numbers", GetType(System. Int32))
dt.Columns.Add( "Characters ")
For i As Integer = 0 To 9
ds.Tables(0).Ro ws.Add(ds.Table s(0).NewRow)
ds.Tables(0).Ro ws(i).ItemArray = _
(New Object() {i.ToString, ChrW(i + 65)})
Next
End Sub
////
\\\Form2 has a datagrid and the form new is like this
Private ds1 As DataSet
Public Sub New(ByVal ds As DataSet)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeCompo nent()
ds1 = ds
'Add any initialization after the InitializeCompo nent() call
DataGrid1.DataS ource = ds1.Tables(0)
End Sub
////

I am curious about that

Cor
"Jan Nielsen"
Hi Cor
No, just one textbox
(I added a jpeg)

Best regards

Jan

"Cor Ligthert" <no************ @planet.nl> skrev i en meddelelse
news:%2******** **********@TK2M SFTNGP09.phx.gb l...
Jan,

A question, is there in your datagrid a comboboxcolumn?

Cor

"Jan Nielsen"
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%******** ********@TK2MSF TNGP14.phx.gbl. ..
Jan,
>New FrmAddGroup(Me. Dataset1)
> myfrmAddGroup.S how()
> myfrmAddGroup = Nothing
>

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.Is Disposed Then
foSearchForm = New FrmSearchForm()
End If
foSearchForm.Sh ow()
///

I hope this helps?

Cor




Nov 21 '05 #8
Hi Cor

Form1 code:
*************** *************** *************** *************** *************** ******
Dim ds As New DataSet()
Dim frm As Form2
Dim i As Integer
Private Sub Form1_Load(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
createDS()
End Sub
Public Sub createDS()
Dim dt As New DataTable()
ds.Tables.Add(d t)
dt.Columns.Add( "Numbers", GetType(System. Int32))
dt.Columns.Add( "Characters ")
For i = 0 To 9
ds.Tables(0).Ro ws.Add(ds.Table s(0).NewRow)
ds.Tables(0).Ro ws(i).ItemArray = _
(New Object() {i.ToString, ChrW(i + 65)})
Next
End Sub

Private Sub Button1_Click_1 (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
frm = New Form2(ds)
' frm.Owner = Me
frm.Show()
End Sub
*************** *************** *************** *************** *************** ******

Form2 code (Entire form class):
*************** *************** *************** *************** *************** ******
Public Class Form2
Inherits System.Windows. Forms.Form
Private ds1 As DataSet
#Region " Windows Form Designer generated code "
Public Sub New(ByVal ds As DataSet)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeCompo nent()
ds1 = ds
'Add any initialization after the InitializeCompo nent() call
DataGrid1.DataS ource = ds1.Tables(0)
'Add any initialization after the InitializeCompo nent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents DataGrid1 As System.Windows. Forms.DataGrid
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()
Me.DataGrid1 = New System.Windows. Forms.DataGrid( )
CType(Me.DataGr id1, System.Componen tModel.ISupport Initialize).Beg inInit()
Me.SuspendLayou t()
'
'DataGrid1
'
Me.DataGrid1.Da taMember = ""
Me.DataGrid1.He aderForeColor = System.Drawing. SystemColors.Co ntrolText
Me.DataGrid1.Na me = "DataGrid1"
Me.DataGrid1.Si ze = New System.Drawing. Size(264, 256)
Me.DataGrid1.Ta bIndex = 0
'
'Form2
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(292, 266)
Me.Controls.Add Range(New System.Windows. Forms.Control() {Me.DataGrid1})
Me.Name = "Form2"
Me.Text = "Form2"
CType(Me.DataGr id1, System.Componen tModel.ISupport Initialize).End Init()
Me.ResumeLayout (False)
End Sub
#End Region
End Class

*************** *************** *************** *************** *************** ******

Now open form2 and add a row
Close form2
Open form2 again and delete the row you just added

Best regards

Jan

"Cor Ligthert" <no************ @planet.nl> skrev i en meddelelse
news:eW******** ********@TK2MSF TNGP09.phx.gbl. ..
Jan,

I do not understand this.
Therefore I added a sample is that something as you are doing this?

\\\form1 with a button
Dim ds As New DataSet
Dim frm As Form2
Private Sub Form1_Load(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
createDS()
frm = New Form2(ds)
frm.Owner = Me
frm.Show()
End Sub
Private Sub Button1_Click(B yVal sender As System.Object, _
ByVal e As System.EventArg s) Handles Button1.Click
ds.Tables(0).Ro ws(2).Delete()
If frm.IsDisposed Then
frm = New Form12(ds)
frm.Show()
Else
frm.TopMost = True
End If
End Sub
Public Sub createDS()
Dim dt As New DataTable
ds.Tables.Add(d t)
dt.Columns.Add( "Numbers", GetType(System. Int32))
dt.Columns.Add( "Characters ")
For i As Integer = 0 To 9
ds.Tables(0).Ro ws.Add(ds.Table s(0).NewRow)
ds.Tables(0).Ro ws(i).ItemArray = _
(New Object() {i.ToString, ChrW(i + 65)})
Next
End Sub
////
\\\Form2 has a datagrid and the form new is like this
Private ds1 As DataSet
Public Sub New(ByVal ds As DataSet)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeCompo nent()
ds1 = ds
'Add any initialization after the InitializeCompo nent() call
DataGrid1.DataS ource = ds1.Tables(0)
End Sub
////

I am curious about that

Cor
"Jan Nielsen"
Hi Cor
No, just one textbox
(I added a jpeg)

Best regards

Jan

"Cor Ligthert" <no************ @planet.nl> skrev i en meddelelse
news:%2******** **********@TK2M SFTNGP09.phx.gb l...
Jan,

A question, is there in your datagrid a comboboxcolumn?

Cor

"Jan Nielsen"

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%******** ********@TK2MSF TNGP14.phx.gbl. ..
> Jan,
>
>
>>New FrmAddGroup(Me. Dataset1)
>> myfrmAddGroup.S how()
>> myfrmAddGroup = Nothing
>>
>
> 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.Is Disposed Then
> foSearchForm = New FrmSearchForm()
> End If
> foSearchForm.Sh ow()
> ///
>
> I hope this helps?
>
> Cor
>
>
>



Nov 21 '05 #9
Jan,

I tested what you sent, however that did not throw an error in the way as
you told it.

Not important, however in my sample is an typor there is on someplaces
form12 what has to be form2 (i changed it in the text)

Cor
Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2192
by: Tonya | last post by:
Hi, Does anyone have any example of how i can manage forms in my application?? I want to be able to reference my form instances that are currently open from other forms. why cant i open and close forms as easily as in VB6??
16
11881
by: David Lauberts | last post by:
Hi Wonder if someone has some words of wisdom. I have a access 2002 form that contains 2 graph objects that overlay each other and would like to export them as a JPEG to use in a presentation. I can do this individually for each graph but this does not help me as I need both on the same JPEG. I thought I would try an export the form that contains both but I am having trouble. (My VBA is self taught and a little knowledge is...
6
4464
by: John | last post by:
Hi Is it possible to close a form through code from within itself without using the form name? I just worry that form name can change and the code will stop working. Thanks Regards
12
3237
by: (Pete Cresswell) | last post by:
I know I can open many instances of a given form, but I've never done it. Now I'm analyzing an application where that seems like just the ticket: Many investment funds, *lots* of data points for each fund, and a desire by the users to see several funds presented side-by-side. Is opening, say, five instances of the same form real-world-doable? -- PeteCresswell
17
8628
by: Barret Bonden | last post by:
As an old programmer just now looking at VB.net I have a question: How does one simply open one form from another ? I don't mean how does one create a new instance of that form , but rather how to refer to THAT form ? And having done this, how does one get data to and from that form ? I have read the MS tutorial on this but it is senselessly complex; there must be a simple, straightforward method, or I can only assume that MS has...
7
3389
by: Terry | last post by:
I have a Mainform with a Statusbar. When opening another form or doing some processing I want to display info in the Statusbar of the Mainform. I have read a lot of articles on this & have come up with the code below. It seems to work(!!!) in that when coding the second form I can see the DisplayStatusMsg of the main form. During debug the code runs through & seemingly executes the call without error. But!...The message is not displayed....
4
3292
by: GGerard | last post by:
Hello I have a program where the user can open as many instances of a form as the user wants. The only limit to how many instances can be opened is determined by the limit of the computer itself (the amount of RAM - I think). When enough instances of this form are opened and the limit of the computer is reached
6
1823
by: Savante | last post by:
I have been writing a datalogging application. It reads in double's into a database. I want to be able to click on a row in a database (holds name of variable and also current value of variable) and then instantiate a new form. I created a new form form2 and then just on double click on a button.... dim form as new form2 form.show
3
3944
by: Jon | last post by:
My main form opens up another form, and from this other form, I'd like to access things in the main form. The problem is that although I know the name of the class of the main form (FormMain) I don't know the name of the instance of it since it was generated by the VS C# Express 2005 designer. In program.cs, I notice that there is the line: Application.Run(new FormMain()); I guess I could replace this with: FormMain fMain = new FormMain()...
5
3311
by: Neil | last post by:
"lyle" <lyle.fairfield@gmail.comwrote in message news:48c3dde7-07bd-48b8-91c3-e157b703f92b@f3g2000hsg.googlegroups.com... Question for you. I'm doing something similar, only, instead of opening the forms all at once, I'm opening them as needed. I have a main form with multiple records; and then I have a pop-up form that the user opens with button. The pop-up form contains one record relating to the current record in the main form (but...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9946
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.