【发布时间】:2010-03-09 18:48:40
【问题描述】:
嗨,
这个问题在网上被问了很多,但似乎都与windows forms和asp.net forms混淆了,所以我最终不得不来这里回答。
我在 VB.NET 中有一个主窗体(一个窗口窗体),它有一个组合框来显示国家列表。从主窗体上的“按钮”激活的子窗体允许用户将国家添加到他们的列表中。但是在添加新条目后,主窗体上的组合框不显示更新(虽然它仍然打开)。我必须退出主窗体并重新启动它才能看到更新。
填充函数如下所示。我在添加新国家后调用此方法,但仍然;不好。我使用了组合框的无效功能,但也没有用。
任何帮助表示赞赏。谢谢
Public Sub PopulateCountry()
Dim rsLocal As New ADODB.Recordset
Try
Dim sSQLCommand As String
Me.CountryList.Items.Clear()
'get the list of countries from the local database
sSQLCommand = " SELECT * FROM CountryList order by CountryDesc"
rsLocal.Open(sSQLCommand, cnn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
'Display All the countries
While rsLocal.EOF = False
Dim Country As New modGV.cbItem
Country .ID = rsLocal.Fields("CountryID").Value
Country.name = rsLocal.Fields("Country Desc").Value.ToString.Trim
Me.CountryList.Items.Add(Country)
rsLocal.MoveNext()
End While
rsLocal.Close()
Catch ex As Exception
Debug.WriteLine("PopulateCountry: exception occurred " & ex.Description)
Finally
If rsLocal.State = ConnectionState.Open Then
rsLocal.Close()
End If
End Try
End Sub
【问题讨论】:
-
不用担心,我明白了。 Populate 方法在 Main 窗体类中,插入新国家的代码在 CountyList 类中。在我在 CountyList 类中创建 Main 窗体类的新实例之前,我必须做的是将 Main 的当前实例从类传递给 CountyList 类,然后使用传递的实例调用 Populate 函数。