2015-01-29 7 views
0

인터페이스를 사용하여 두 개의 다른 객체로 콤보 박스를 채우고 싶습니다. 이것이 내가 현재 가지고있는 것입니다. 이 작동하지만 지금은 각 개체에 대한 표시 멤버 및 값 멤버를 갖고 싶습니다, 어떻게 그렇게합니까?두 개의 다른 객체로 콤보 박스 채우기

Controller.cs에서

public List<IMusic> Populate() 
     { 
      List<IMusic> newList = new List<IMusic>(); 

      foreach(Track t in tr.GetAllTracks()){ 
       newList.Add(t); 
      } 

      foreach (Artist a in ar.GetAllArtists()) 
      { 
       newList.Add(a); 
      } 
      return newList; 
     } 

IMusic.cs

interface IMusic 
    { 

    } 

데이터 소스와 콤보 :

cBMainScreen_Search.DataSource = controller.Populate(); 

으로 GetAllTracks()

GetAllArtists() :

public List<Artist> GetAllArtists() 
     { 
      return db.Artist.ToList(); 
     } 

답변

0

그냥 설정하여 인터페이스의 일부 속성 : (IMusic를 구현해야합니다) 트랙 클래스 다음

interface IMusic 
{ 
    string Display { get; set; } 
    string Value { get; set; } 
} 

:

public string Display 
{ 
    get 
    { 
     return this.TrackName; 
    } 
    set 
    { 
     this.TrackName= value; 
    } 
} 

public string Value 
{ 
    get 
    { 
     return this.TrackID; 
    } 
    set 
    { 
     this.TrackID= value; 
    } 
} 

그리고 당신의 아티스트 클래스 (IMusic도 구현) :

public string Display 
{ 
    get 
    { 
     return this.ArtistName; 
    } 
    set 
    { 
     this.ArtistName= value; 
    } 
} 

public string Value 
{ 
    get 
    { 
     return this.AritstID; 
    } 
    set 
    { 
     this.AritstID= value; 
    } 
} 
관련 문제