Hatena::ブログ(Diary)

憂国のプログラマ Hatena版

快走韋駄天
Amazon

2010-11-28 WPF 超入門

Q029. ComboBox に Datasource は指定できないのですか?

| 10:25 | Q029. ComboBox に Datasource は指定できないのですか?を含むブックマーク


A. いったん IListSource にキャストして ComboBox.ItemsSource プロパティに設定するか、もしくは DataTable.DefaultView で設定できます。

C#

	DataTable dt = new DataTable();
	comboPrefectures.ItemsSource = dt.DefaultView;
	// comboPrefectures.ItemsSource = ((IListSource)dt).GetList();
	comboPrefectures.DisplayMemberPath = "value";
	comboPrefectures.SelectedValuePath = "sub_id";

VB.NET

	Dim dt As New DataTable()
	comboPrefectures.ItemsSource = dt.DefaultView
	' comboPrefectures.ItemsSource = CType(dt, IListSource).GetList()
	comboPrefectures.DisplayMemberPath = "value"
	comboPrefectures.SelectedValuePath = "sub_id"

#2011/09/29 修正



トラックバック - http://d.hatena.ne.jp/hilapon/20101128/1295832349