刷新列表视图的下拉值

时间:2013-12-22 10:36:35

标签: vb.net visual-studio-2010 visual-studio

我有一个显示部门的下拉列表,然后在列表视图中显示相应的值。我想要做的是当在下拉列表中选择一个部门时,列表视图将填充该部门的值。如果我单击另一个单选按钮然后再次单击我的原始按钮,它会起作用,但如果我保持相同的选择则不行。

有没有办法从下拉列表中自动刷新列表视图。而非onChange事件?我对vb.Net比较新,所以对此的任何帮助都会帮助我学习曲线。我已经在我的代码中包含了我认为应该完成的方式,但它无法正常工作。非常感谢

更新代码

单选按钮点击事件

Private Sub rdbBoxReturn_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdbBoxReturn.CheckedChanged

        ' query db for boxes that are being returned.

        DBConnection.connect()

        sql = "SELECT * from Boxes WHERE Customer = '" & cmbCustomer.Text & "' AND Dept = '" & cmbDept.Text & "' AND Status = 'o' ORDER BY Box ASC"
        'Dim sql As String = "SELECT * from Boxes WHERE Customer = ? AND Status = 'i'"

        Dim cmd As New OleDb.OleDbCommand

        'cmd.Parameters.AddWithValue("@p1", cmbCustomer.Text)

        cmd.CommandText = sql
        cmd.Connection = oledbCnn
        dr = cmd.ExecuteReader

        lvSelectRequestItems.Items.Clear()

        While dr.Read()

            Dim LV As New ListViewItem
            LV.SubItems.Clear()
            With (LV)

                .UseItemStyleForSubItems = False
                .Text = dr("Box").ToString()
                .SubItems.Add(dr("CustRef").ToString())
                .SubItems.Add(dr("Dept").ToString())

            End With

            lvSelectRequestItems.Items.Add(LV)

        End While



        cmd.Dispose()
        dr.Close()
        oledbCnn.Close()

        lblQuantity.Text = "Quantity of Boxes"

        lblQuantity.Visible = True
        txtBoxQuantity.Visible = True

        lvSelectedItems.Visible = True
        lvSelectRequestItems.Visible = True
        btnRemoveItem.Visible = True

        lblBoxSize.Visible = False
        gbxBoxType.Visible = False

        lblServiceLevel.Visible = True
        gbxServiceLevel.Visible = True

    End Sub
  

Private Sub cmbDept_SelectedIndexChanged(ByVal sender As   System.Object,ByVal e As System.EventArgs)句柄   cmbDept.SelectedIndexChanged

    ' This is the routine to populate the requested by box with values from customer

    DBConnection.connect()

    sql = "SELECT * from Contacts WHERE Customer = ?"

    Dim cmd As New OleDb.OleDbCommand

    cmd.Parameters.AddWithValue("@p1", cmbCustomer.Text)

    cmd.CommandText = sql
    cmd.Connection = oledbCnn
    dr = cmd.ExecuteReader

    lvSelectRequestItems.Items.Clear()

    While dr.Read()

        cmbRequestBy.Items.Add(dr("Name"))

    End While

    lvSelectRequestItems.Refresh()

    cmd.Dispose()
    dr.Close()
    oledbCnn.Close()
    'rdbBoxIntake.Checked = True


End Sub

0 个答案:

没有答案