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
>
>
>