2011-04-21 5 views
0

내 DAL에 SubSonic 2.2를 사용하고 개요 클래스 수준에 따라 들여 쓰기가있는 다른 속성을 포함하는 문자열을 반환하는 계산 된 속성으로 내 클래스 중 하나를 확장했습니다. 해당 항목이 발생합니다. 속성에 대한 코드는 다음과 같습니다. 문제는 내가이 속성을 폼의 ListBox 컨트롤에 대한 DisplayMember로 사용하려고하면 (처음 쓴 이유) 작동하지 않는다는 것입니다. ListBox는 ValueMember로 설정된 ID 속성을 표시하는 것으로 되돌아갑니다. 속성이 작동하는지 테스트하기 위해 ListBox를 채우는 개체 컬렉션을 반복하고 MessageBox.Show (obj.property)를 사용하여 실제로 찾고있는 값을 반환했는지 확인했습니다. 나는 뭔가를 놓치고 있습니까, 아니면이게 효과가 있습니까? btw - 들여 쓰기를 수행하는 더 좋은 방법이있을 수 있지만 그 순간에 내가 쫓고있는 것이 아닙니다, 감사합니다!Listbox.DisplayMember는 계산 된 속성의 값을 표시하지 않습니다.

코드는 다음과 같습니다

public partial class InteriorsCategory : ActiveRecord, IActiveRecord { public string ListDisplay { get { string returnValue = "";

  for (int i = 1; i < this.SpecLevel; i++) 
      { 
       returnValue += " "; 
      } 
      returnValue += this.CategoryName; 
      return returnValue; 
     } 
    } 
} 

<>

I definitely get data in my collection and the binding I'm doing is exactly the same as yours (binding code posted below). The return value of the ListDisplay property that I'm using is a string concatenation of two values in the object. Think of it as a "full name" property that concatenates the FirstName a space and the LastName properties into a single string which it returns. I am trying to bind the ListDisplay property to the DisplayMember property of the listbox, but all that shows in the listbox is the Id field which I am binding to the ValueMember.

private void FillCategories() { lstPackageCategories.DataSource = new InteriorsCategoryCollection().Load(); lstPackageCategories.DisplayMember = "CategoryName"; lstPackageCategories.ValueMember = "Id";
((InteriorsCategoryCollection)(lstPackageCategories.DataSource)).Sort("SpecSection", true);
lstPackageCategories.SelectedItem = lstPackageCategories.Items[0];

currentCategory = (InteriorsCategory)lstPackageCategories.SelectedItem; RefreshAvailableItems(); }

답변

0

당신의리스트 박스의 결합에 문제가처럼 컬렉션에 데이터를 볼 수는, 다음이 들린다면 . 다음은 SubSonic 컬렉션을 사용하여 ListBox를 바인딩하는 방법의 예입니다. 위의 예에서

ISOCountryCodeCollection countrys = 
     new ISOCountryCodeCollection().OrderByAsc(ISOCountryCode.Columns.Country).Load(); 

    Country.DataSource = countrys; 
    Country.DataValueField = "ThreeChar"; 
    Country.DataTextField = "Country"; 
    Country.DataBind(); 

, 나는 "DataTextField"에 "DataValueField"및 전체 국가의 이름으로 3 문자 국가 코드를 결합하고있다.