2017-04-25 89 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上得到一個錯誤 –