2017-04-25 82 views
2

所以基本上,我希望能够将组合框中的所有文本项目发送到不同表单上的标签以进行打印。将Visual Basic '15组合框文本添加到标签

这是我的代码片段;

 ' Shows the yacht types in a new called frmYachtTypeSummary which then can be printed 
    frmYachtTypeSummary.lblYachtTypeSummary.Text = cboYachtType.Text.ToString 
    frmYachtTypeSummary.ShowDialog() 

当我使用我在这里的内容时,如果我在组合框中选择一个对象,它将打印到所需的形式。我想要做的是将整个组合框打印到表单中。

回答

0
Dim allItems as String, item as Object 
For Each item In cboYachtType.Items 
    allItems = allItems & item.toString() & vbCrLf 
Next 
frmYachtTypeSummary.lblYachtTypeSummary.Text = allItems 

p.s .:这个答案开始作为一个VBA的答案,但它似乎是OP有一个标签错误。

+0

我试着用你给我的代码,它告诉我所有的item都在声明之前使用。此外,你是对的,我不知道我正在使用的是什么,因为我仍然习惯它。我知道它是通过Visual Studio,而类是Visual Basic。我也在创建窗体。 –

+0

你绝对在VB.Net上。 'Dim allItems as String =“”,item as Variant'。也可以尝试使用'.Text'来代替'.Caption'。 ' –

+0

首先,我想表示感谢您为我提供的所有帮助。所以我再次尝试了代码,但Variant并未出现。最接近它的是VariantType,它让我在我的cboYachtType.Text上得到一个错误 –