这让我疯了,我确信我在这里遗漏了一些明显的东西。 我有一个数据集,摘要标签控件是一个由几个数据集列组成的字符串。它看起来像这样;
Dim EngDetailsStr As String
Dim str1 As String = MDataSet.EnginesPool.Item(i).Item("EngInstalledPosition").ToString '(OR REMOVE THE .TOSTRING, it still dont work)
Dim str2 As String = MDataSet.EnginesPool.Item(i).Item("EngModelDisplayName").ToString
EngDetailsStr = ("Engine Location - " & str1 & "-" & str2)
或(如果我尝试过:)
EngDetailsStr = "Engine Serial: -" & MDataSet.EnginesPool.Item(i).Item("EngInstalledPosition")
两者都以;
结尾Label1.text = EndDetailsStr
我做的是什么?字符串引用为:“引擎位置 - ”没有将数据集值附加到字符串。
数据集值不是空白,它们只是字符串,(在代码中进一步检查)。为什么这不起作用?
是否需要将一些特殊的数据库字符串转换为普通字符串?
感谢互联网,
编辑:整个循环编码
For i As Integer = 0 To MaintraxDataSet.EnginesPool.Rows.Count - 1
EngLineLabel(i) = New Label
With EngLineLabel(i)
.Name = "EngLabel" & i
.ForeColor = Color.White
.Visible = True
Dim pointlabel As Point
pointlabel.X = 60
pointlabel.Y = 55 + (i * 25)
.Location = pointlabel
.BringToFront()
Dim EngDetailsStr As String
If IsDBNull(MaintraxDataSet.EnginesPool.Item(i).Item("EngSerialNumber")) Then
EngDetailsStr = ("Engine " & i & " Not found. Data Error.")
Else
Dim str1 As String = MaintraxDataSet.EnginesPool.Item(i).Item("EngInstalledPosition").ToString
Dim str2 As String = MaintraxDataSet.EnginesPool.Item(i).Item("EngModelDisplayName").ToString
EngDetailsStr = "Engine Location - " & str1 & "-" & str2
End If
.Text = EngDetailsStr
End With
'Create the label
Panel1.Controls.Add(EngLineLabel(i))
Next
答案 0 :(得分:0)
添加到标签控件时,它可以正常工作:
.AutoSize = true
显然,如果动态创建标签,则默认设置为false。添加数据集中的文本使得字符串为标签控件的长度,因此最后一个字符串将被截断。
因此:'
Dim str1 As String = MaintraxDataSet.EnginesPool.Item(i).Item("EngInstalledPosition").ToString
Dim str2 As String = MaintraxDataSet.EnginesPool.Item(i).Item("EngModelDisplayName").ToString
NewLabel1.text = "Engine Location - " & str1 & "-" & str2
会截断字符串并仅显示"引擎位置 - "
但是:'
NewLabel1.autosize = true
NewLabel1.Text = "Engine Location - " & str1 & "-" & str2
工作正常。
思想ID将此留在这里以防其他人有此问题。感谢。