使comboxbox绑定到具有引用类型的属性 [英] Making a comboxbox bound to the property with reference type

查看:57
本文介绍了使comboxbox绑定到具有引用类型的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了两个类:人员和费用,其中费用最多可以有一个可归还人员.

I created two classes: Person and Expense in which an expense might have at most a reposible person.

Public Class Person
  ...
End Class

Public Class Expense
  Private m_descr  As String 'Describe the expense
  Private m_amount As Double 'Amount expensed
  Private m_person As Person 'A person who is responsible for an expense

  Public Property Description() As Double ... End Property
  Public Property Amount() As Double ... End Property
  Public Property Person() As Person ... End Property
  ...
End Class



如果我想将费用的父项绑定到下拉列表项绑定到人"列表的Combox上,当下拉列表中的人更改该费用的负责人时,我该怎么做(在VB.Net中)



If I want to bind the property Parent of an expense to a Combox with dropdonw items bound to a list of Persons, How can I do (in VB.Net) in order to change the responsible person of this expense when a person in the dropdown of this combobox was chosen?

推荐答案

如果要将组合框绑定到类,则您的类需要实现如何将Windows窗体组合框控件绑定到数据 [ IList(属于T) [
If you want to bind combobox to your class, your class needs to implement IList[^] Interface.
This links would be helpful too:
How to bind a windows forms combobox control to data[^]
IList(of T)[^]

If you want to change Person for Expense, change the Person property:
Public Property Person(ByVal _person As Person) As Person
    Get
        Return m_Person
    End Get
    Set(ByVal _person As Person)
        m_Person = _person
    End Set
End Property


这篇关于使comboxbox绑定到具有引用类型的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆