简体   繁体   English

如何将getitemdata转换并将itemdata从vb6组合设置为vb.net组合方法

[英]how to convert getitemdata and set itemdata from vb6 combo to vb.net combo methods

hi we are migrating vb6 to vb.net .In vb 6 combobox methods are not supported in vb.net 嗨,我们正在将vb6迁移到vb.net。在vb 6中,vb.net不支持组合框方法

VB6.GetItemString(cboEditBox(0), cboEditBox(0).SelectedIndex)
VB6.Format(VB6.GetItemData(cboEditBox(0), cboEditBox(0).SelectedIndex)
VB6.Format(frmTableRate.txtRate.Text, "##0.0####")
VB6.SetItemData(cboEditBox(0), cboEditBox(0).SelectedIndex
CheckUsage(sSQLWhere, VB6.Format(frmTableRate.Tag), sMsg, bUsed) 
VB.Left(VB6.GetItemString(lstRates, lstRates.SelectedIndex)
sTableID = VB6.Format(VB6.GetItemData(cboEditBox(0), cboEditBox(0).SelectedIndex), "000")

Here's a simple sample of how combo box items in VB.NET could easily store display values and data values. 这是有关VB.NET中组合框项目如何轻松存储显示值和数据值的简单示例。 To try it, just paste this code on an empty form called Form1. 要尝试,只需将此代码粘贴到一个名为Form1的空窗体上。 It will create the control and hook up event handlers by itself. 它将自行创建控件并连接事件处理程序。

Public Class ComboItem
   Public Property DisplayString As String
   Public Property ItemData As Object
   Public Sub New(DisplayString As String, Optional ItemData As Object = Nothing)
      Me.DisplayString = DisplayString
      Me.ItemData = ItemData
   End Sub
End Class

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
   Dim cboEditBox As New ComboBox
   Controls.Add(cboEditBox)
   Dim comboData As New System.ComponentModel.BindingList(Of ComboItem)
   cboEditBox.DataSource = comboData
   cboEditBox.DisplayMember = "DisplayString"
   cboEditBox.ValueMember = "ItemData"

   comboData.Add(New ComboItem("One"))
   ' Demonstrate setting item data along with creation of the list items
   comboData.Add(New ComboItem("Two", "First duplicate"))
   comboData.Add(New ComboItem("Two", "Second duplicate"))

   ' Demonstrate SetItemData alternative
   DirectCast(cboEditBox.SelectedItem, ComboItem).ItemData = "The first item"
   AddHandler cboEditBox.SelectedIndexChanged, AddressOf cboEditBox_SelectedIndexChanged
End Sub

Private Sub cboEditBox_SelectedIndexChanged(sender As Object, e As EventArgs)
   Dim target As ComboBox = DirectCast(sender, ComboBox)
   ' Demonstrate GetItemData alternative
   MsgBox(target.SelectedValue)
End Sub

Note, by using BindingList (instead of an array or regular List), we ensure that even after the ComboBox is initialized, adding or removing elements from the list directly will be reflected in the combo box without having to refresh the combo box DataSource property. 注意,通过使用BindingList(而不是数组或常规List),我们确保即使在初始化ComboBox之后,直接从列表中添加或删除列表中的元素也将反映在组合框中,而无需刷新组合框的DataSource属性。 If you want to manually refresh the combo box DataSource property manually, a simple array or list could be used instead. 如果要手动刷新组合框的DataSource属性,则可以使用简单的数组或列表代替。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM