在 DataGridView 中显示自定义类枚举属性的可编辑下拉列表
我将自定义类绑定到 Datagridview 并希望显示 Enum 属性之一的可编辑组合框。
Public Class Contact
Public Enum GenderTypes
Male
Female
End Enum
Private _Firstname As String
Private _Lastname As String
Private _Gender As GenderTypes
Public Property FirstName() As String
Get
Return Me._Firstname
End Get
Set(ByVal value As String)
Me._Firstname = value
End Set
End Property
Public Property LastName() As String
Get
Return Me._Lastname
End Get
Set(ByVal value As String)
Me._Lastname = value
End Set
End Property
Public Property Gender() As GenderTypes
Get
Return Me._Gender
End Get
Set(ByVal value As GenderTypes)
Me._Gender = value
End Set
End Property
End Class
在 Form1 中,我绑定列表(联系人),如下所示。
Dim mContacts As List(Of Contact) = New List(Of Contact)
dgContacts.DataSource = mContacts
现在,当我在 datagridview 中运行应用程序时,没有为自定义类的性别枚举属性创建可编辑的组合框。我尝试创建自定义 EnumConverter 但没有将枚举属性设置为可编辑下拉列表。
请让我知道如何在 datagridview 中获取自定义类枚举属性的可编辑组合框/下拉菜单。
I am binding custom class to Datagridview and want to show Editable combobox for one of the Enum property.
Public Class Contact
Public Enum GenderTypes
Male
Female
End Enum
Private _Firstname As String
Private _Lastname As String
Private _Gender As GenderTypes
Public Property FirstName() As String
Get
Return Me._Firstname
End Get
Set(ByVal value As String)
Me._Firstname = value
End Set
End Property
Public Property LastName() As String
Get
Return Me._Lastname
End Get
Set(ByVal value As String)
Me._Lastname = value
End Set
End Property
Public Property Gender() As GenderTypes
Get
Return Me._Gender
End Get
Set(ByVal value As GenderTypes)
Me._Gender = value
End Set
End Property
End Class
In Form1 i am binding List(Of Contact) like following.
Dim mContacts As List(Of Contact) = New List(Of Contact)
dgContacts.DataSource = mContacts
Now,when i run the application in datagridview didn't create editable combobox for gender enum property of my custom class. I tried to create custom EnumConverter but didn't make the enum property to editable dropdown.
Please let me know how i'll get the editable combobox/dropdown in datagridview for my custom class enum property.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 datagridview 的 EditingControlShowing 事件中,将该列组合框的下拉样式设置为 DropDown。下面是示例。
这应该使您的性别组合框可编辑。
In the EditingControlShowing event of your datagridview, set the drop down style of that column comobo box to DropDown. Below is the sample.
This should make your gender combo box editable.