在自定义类vb.net中未定义“记录”类型

问题描述

我正在下面的线程中创建多行组合框。我目前正在使用Visual Studio 2019,该线程来自2013。

Any way for a combo box with 2 values per line?

我复制的代码

    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

我创建了一个名为MultiLineComboBox的类,严格按照说明进行操作,并说“未定义类型'Record'”。我一直在搜索“记录”或DirectCast类型的答案(例如https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/directcast-operator),但到目前为止,它们都没有帮助我。

我的声誉当前为

(在出现VS或.NET版本的情况下添加标签visual-studio-2019和.net-4.7.2

解决方法

阅读整个答案。 Record类在此处声明;您也需要它,并且您想要更改代码以匹配组合框的字段。