从visual basic中的数据源更新列表框

时间:2017-03-19 20:40:08

标签: vb.net

我的表单中有一个列表框,可以自动填充数据源中的信息。然后我打开第二个表单来添加/删除数据集中的人员。当我保存并关闭它时,更新在数据集本身完成,但不在列表框中完成。我添加了一个按钮,试图刷新它,我没有运气..这是我尝试过的一个例子。

       Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    ListBox1.DataSource = Nothing
    ListBox1.ValueMember = Nothing
    'ClientInfoTableAdapter.Update(DaycareDataSet2)
    'ListBox1.DataBindings.Clear()
    'ListBox1.Items.Clear()
    '' ClientInfoTableAdapter.Fill(DaycareDataSet2.ClientInfo)
    ListBox1.DataSource = DaycareDataSet2.ClientInfo
    ListBox1.DisplayMember = "ClientFullName"
    ListBox1.ValueMember = "id"
    'ListBox1.SelectedIndex = ListBox1.Items.Count - 1
    listbox1.update()


End Sub      

1 个答案:

答案 0 :(得分:0)

  Ok so I seemed to have written a small sub to refresh the data? from what I understand.. my list finally updates now.. 

Public Sub RefreshDatabase()

        If Not cnn.State = ConnectionState.Open Then
        cnn.Open()
    End If
    Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM ClientInfo ORDER BY ID", cnn)
    Dim dt As New DataTable
    da.Fill(dt)
    Me.listboxClients.DataSource = dt
    Me.listboxClients.DisplayMember = "ClientFullName"
    cnn.Close()
End Sub