0

DALにSubSonic2.2を使用しており、アイテムが発生するアウトラインのレベルに基づいてインデントされた別のプロパティを含む文字列を返す計算プロパティを使用して、クラスの1つを拡張しました。プロパティのコードは次のとおりです。問題は、このプロパティをフォームのListBoxコントロールのDisplayMemberとして使用しようとすると(最初に作成した理由)、機能しないことです。ListBoxは、ValueMemberとして設定されているIDプロパティの表示に戻ります。プロパティが機能していることをテストするために、ListBoxに入力しているオブジェクトのコレクションをループし、MessageBox.Show(obj.property)を使用して、探している値が実際に返されていることを確認しました。私は何かが足りないのですか、それともこれはうまくいくべきですか?ところで-インデントを行うためのより良い方法があるかもしれませんが、それは '

コードは次のとおりです。

パブリック部分クラスInteriorsCategory:ActiveRecord、IActiveRecord {{ パブリック文字列ListDisplay {{ 得る {{ 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(); }

4

1 に答える 1

0

コレクション内のデータを表示できる場合は、ListBox のバインドに問題があるようです。SubSonic の値のコレクションを使用して ListBox をバインドする方法の例を次に示します。

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

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

上記の例では、3 文字の国コードを「DataValueField」にバインドし、完全な国名を「DataTextField」にバインドしています。

于 2011-04-27T16:53:15.647 に答える