[英]Type “Record” is not defined in custom class vb.net
I'm following the thread below to create the multi-line combobox.我正在按照下面的线程创建多行组合框。 I'm currently using Visual Studio 2019, and that thread is from 2013.
我目前正在使用 Visual Studio 2019,该线程来自 2013 年。
Any way for a combo box with 2 values per line? 每行有 2 个值的组合框的任何方式?
Code that I copied:我复制的代码:
Public Class MultiLineComboBox : Inherits ComboBox
Public Sub New()
' Call the base class.
MyBase.New()
' Typing a value into this combobox won't make sense, so make it impossible.
Me.DropDownStyle = ComboBoxStyle.DropDownList
' Set the height of each item to be twice its normal value
' (because we have two lines instead of one).
Me.ItemHeight *= 2
End Sub
Protected Overrides Sub OnDrawItem(e As DrawItemEventArgs)
' Call the base class.
MyBase.OnDrawItem(e)
' Fill the background.
e.DrawBackground()
' Extract the Record object corresponding to the combobox item to be drawn.
If (e.Index >= 0) Then
Dim record As Record = DirectCast(Me.Items(e.Index), Record)
' Format the item's caption string.
Dim caption As String = String.Format("ID: {0}{1}Name: {2}", record.UniqueID.ToString(), Environment.NewLine, record.Name)
' And then draw that string, left-aligned and vertically centered.
TextRenderer.DrawText(e.Graphics, caption, e.Font, e.Bounds, e.ForeColor, TextFormatFlags.Left Or TextFormatFlags.VerticalCenter)
End If
' Finally, draw the focus rectangle.
e.DrawFocusRectangle()
End Sub
End Class
I created a class named MultiLineComboBox, followed the instruction exactly, and it says "Type 'Record' is not defined."我创建了一个名为 MultiLineComboBox 的类,完全按照说明进行操作,它说“未定义类型‘记录’”。 I have been searching for answers on the type "record" or DirectCast (eg https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/directcast-operator ), but none of them has helped me so far.
我一直在寻找关于“记录”或 DirectCast 类型的答案(例如https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/directcast-operator ),但没有到目前为止,他们帮助了我。
My reputation is currently <50 so I cannot leave a comment on the answer of that thread either.我的声誉目前 <50,所以我也不能对该线程的答案发表评论。 Could you all please help me with this?
大家能帮我解决这个问题吗?
(added tag visual-studio-2019 and .net-4.7.2 in case VS or .NET version is the issue) (如果 VS 或 .NET 版本是问题,添加了标签 visual-studio-2019 和 .net-4.7.2)
Read the whole answer.阅读整个答案。 The
Record
class is declared there; Record
类在那里声明; you need it, too, and you want to change the code to match the fields for your combobox.您也需要它,并且想要更改代码以匹配组合框的字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.