Hi Tore,
I feel so sorry mis-pasting the code, I feel really aplogize for this
mistake.
Here is the my code.
If you still have problems on this issue,please let me know.
<code>
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'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 MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.MenuItem2 = New System.Windows.Forms.MenuItem
Me.ComboBox1 = New System.Windows.Forms.ComboBox
Me.SuspendLayout()
'
'MainMenu1
'
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem()
{Me.MenuItem1})
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem()
{Me.MenuItem2})
Me.MenuItem1.Text = "File"
'
'MenuItem2
'
Me.MenuItem2.Index = 0
Me.MenuItem2.Text = "New"
'
'ComboBox1
'
Me.ComboBox1.Location = New System.Drawing.Point(152, 24)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(121, 20)
Me.ComboBox1.TabIndex = 1
Me.ComboBox1.Text = "ComboBox1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.ComboBox1)
Me.IsMdiContainer = True
Me.Menu = Me.MainMenu1
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Public dsMain As New DataSet
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem2.Click
Dim frmChild As New ChildForm
frmChild.MdiParent = Me
frmChild.Show()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim dtMain As New DataTable("Table")
dtMain.Columns.Add("Id", System.Type.GetType("System.Int32"))
dtMain.Columns.Add("Name", System.Type.GetType("System.String"))
dtMain.Rows.Add(New Object() {1, "aaa"})
dtMain.Rows.Add(New Object() {2, "bbb"})
dsMain.Tables.Add(dtMain)
ComboBox1.DataSource = dsMain
ComboBox1.DisplayMember = "Table.Name"
End Sub
Private Class ChildForm
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'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 ComboBox1 As System.Windows.Forms.ComboBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.ComboBox1 = New System.Windows.Forms.ComboBox
Me.SuspendLayout()
'
'ComboBox1
'
Me.ComboBox1.Location = New System.Drawing.Point(16, 16)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(121, 20)
Me.ComboBox1.TabIndex = 0
Me.ComboBox1.Text = "ComboBox1"
'
'ChildForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(192, 69)
Me.Controls.Add(Me.ComboBox1)
Me.Name = "ChildForm"
Me.Text = "ChildForm"
Me.ResumeLayout(False)
End Sub
#End Region
Private dsChild As DataSet
Private Sub ChildForm_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
dsChild = CType(Me.MdiParent, Form1).dsMain
ComboBox1.DataSource = dsChild.Copy
ComboBox1.DisplayMember = "Table.Name"
End Sub
End Class
End Class
</code>
--
Ying-Shen Yu
Ying-Shen Yu said:
Hi Tore,
To my understanding now, you have some datasets in an MDI Application and
you want to use them as datasources for combo boxes in some child forms. I
write a small test program.
Hope is helpful to you, if you find this program doesn't fit your needs or
still have problem on this issue, please be free to let me know!
<code>
'I make a new instance of the FormMenu which is my
startup form
Dim FormM As New FormMenu
'Then I refer to the public dataset of FormMenu from
another form
'and display the number of rows, always displays 0 as
answer, which is wrong result.
MsgBox(FormM.DS_OrderGetStates1.Tables
("PN_States").Rows.Count)
'(At this point the dataset of Formmenu holds 7 rows)
'If I try to make a view, it also counts 0 rows, which is
wrong
DataView1.Table = FormM.DS_OrderGetStates1.Tables
("PN_States")
MsgBox(DataView1.Count())
'If I run this codeline in the startup (main) form
itself,
it responds with 7, which is correct number of rows:
MsgBox(DS_OrderGetStates1.Tables("PN_States").Rows.Count)
</code>
Best regards,
Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!
--------------------
| Content-Class: urn:content-classes:message
| From: "Tore Gylver" <
[email protected]>
| Sender: "Tore Gylver" <
[email protected]>
| Subject: How can I copy datasets between windows forms
| Date: Tue, 14 Oct 2003 03:28:19 -0700
| Lines: 47
| Message-ID: <
[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcOSPeLQ4fHBi8TJSseI57687U8zow==
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:54388
| NNTP-Posting-Host: TK2MSFTNGXA12 10.40.1.164
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| I am fairly new to .Net and need to be pointed in the
| right direction.
|
| I have downloaded a number of datasets from a webservice
| to a windows forms client. The datasets are fairly small
| (typically 10 rows) and are used as source for comboboxes
| throughout my application.
|
| To speed up the client my intention was to download these
| datasets at startup and then distribute the datasets to
| the forms containing the comboboxes. My VB code does not
| work as planned.
|
| Here is some example code in the startup form of my
| application:
|
| Public Function GetOrderStates() As DataSet
| Dim DSTest As New DataSet
| DSTest = Me.DS_OrderGetStates1.Copy
| GetOrderStates = DSTest
| End Function
|
|
|
| here is test code on another form. It seems like the
| datset schema is transferred, but no dropdown list is
| available for the combobox.
|
| Private Sub Button1_Click(ByVal sender As System.Object,
| ByVal e As System.EventArgs) Handles Button1.Click
| Dim FormM As New FormMenu, DS As DataSet
|
| DS = FormM.GetOrderStates.Copy
|
| With Me.ComboStateOfOrders
| .DataSource = DS.Tables("PN_States")
| .DisplayMember = "StateName"
| .ValueMember = "StateCode"
| End With
|
| End Sub
|
|
|
| Regards
|
| Tore Gylver
|