リストボックスにバインドされたbindingsourceから行データを取得する

StackOverflow https://stackoverflow.com/questions/811506

  •  03-07-2019
  •  | 
  •  

質問

次のようなリストボックスがあります:

list.DataSource = bindingSource;
list.DisplayMember = "column_name";

後で bindingSource.Current を使用して、選択したアイテムの ID DataSet から取得します。以前に bindingNavigator bindingSource でこれを実行しました。ここで、 Current DataRowView を返すので、キャストできます完了です:

Int32.Parse(((DataRowView)bindingSource.Current)["id"].ToString())

しかし、この場合、 Current DataViewManagerListItemTypeDescriptor オブジェクトを返し、キャストできません。

ご意見をお寄せください!

ダニエル

役に立ちましたか?

解決

list.SelectedItem には、選択した行の DataRowView が含まれている必要があります。その後、次のことができます。

var row = (MyRowType)((DataRowView)list.SelectedItem).Row;
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top