我正在使用与此类似的代码来使用数据库中的项目填充组合框。显示工作正常,但是当我尝试获取combobox.SelectedValue
它时,它返回一个 DataRowView,我需要一个整数。显然这是因为我没有将值转换为整数,但是函数CInt(cboPosition.SelectedValue)
抛出了 InvalidCastException。有什么方法可以让 ValueMember 的类型成为整数?
Dim cn As New SqlConnection(CreditDisputesLogConn)
Dim cmd As New SqlCommand("CustomersLookup", cn)
Dim da As New SqlDataAdapter(cmd)
cmd.CommandType = CommandType.StoredProcedure
Try
Dim dt As New DataTable
da.Fill(dt)
uxCustomerName.DataSource = dt
uxCustomerName.DisplayMember = "CustomerName"
uxCustomerName.ValueMember = "CustomerID"
uxCustomerName.SelectedIndex = -1
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
cn.Close()
cn.Dispose()
End Try