我希望Combobox在添加条目时立即更新。我可以使用与datagridview相同的代码吗?

时间:2015-06-12 20:25:15

标签: sql vb.net datagridview combobox

我使用以下代码在输入新条目后立即更新datagridview。

computeDistanceBetween() – Returns the distance, in meters, between two 
latitude/longitude coordinates.

computeHeading() – Returns the bearing, in degrees, between two 
latitude/longitude coordinates.

computeArea() – Returns the area, in square meters, of a closed path on the 
Earth.

interpolate() – Returns the latitude/longitude coordinates of a point that 
lies a given fraction of the distance between two given points. You can use 
this to animate a marker between two points, for example.

我希望在添加新条目后立即更新组合框,但我只想显示一列。如何修改此代码才能执行此操作!? Thankis!

1 个答案:

答案 0 :(得分:0)

而不是绑定表,循环遍历其行并仅添加您希望显示的列:

    Dim constring As String = "server=classified;database=classified"
    Using con As New SqlConnection(constring)
        Using cmd As New SqlCommand("SELECT * FROM Autos", con)
            cmd.CommandType = CommandType.Text
            Using sda As New SqlDataAdapter(cmd)
                Using dt As New DataTable()
                    sda.Fill(dt)

                    For Each dr As DataRow In dt.Rows

                        ComboBox1.Items.Add(dr.Item("ColumnYouWishToDisplay").ToString())

                    Next

                End Using
            End Using
        End Using
    End Using