2017-03-06 5 views
1

クラスオブジェクトにバインドされたリストから値を取得するにはどうすればよいですか? 私はクラスとそのクラスのリストを持っています。イムは、このc#WPFクラスオブジェクトにバインドされたリスト<>から値を取得する

private void loadAccountBalance(string total, string amount, string transaction, string date) 
    { 
     accountBalance_lst.Add(new accountBalanace_cls() 
     { 
      accountBalanceTotal = total, 
      accountBalanceAmount = amount, 
      accountBalanceTransaction = transaction, 
      accountBalanceDate = date 
     }); 
     accountsBalance_grd.Items.Refresh(); 
    } 

のように一覧表示するには追加すること、これが

 public class accountBalanace_cls 
    { 
     public string accountBalanceTotal { get; set; } 
     public string accountBalanceAmount { get; set; } 
     public string accountBalanceTransaction { get; set; } 
     public string accountBalanceDate { get; set; } 
    } 

私のクラスであり、これは私がやりたいことは、私はあなたを願っています。このようなものであるリストの私の宣言

 List<object> accountBalance_lst = new List<object>(); 

です私がここで成し遂げようとしていることを理解するでしょう

 int total = accountBalance_lst[1].AccountBalanceTotal; 
+0

なぜtagedでタイトルが付けられましたか?** wpf **?私はwpfの何も見たことがありませんでした。 –

答えて

0

accountBalance_lstのタイプはList<object>で、AccountBalanceTotalの定義を含んでいません。 List<object>の具体的な理由がない場合は、代わりにList<accountBalanace_cls>としてください。私は完全にあなたの質問を理解していてください、代わりにこれを行うの

int total = ((accountBalanace_cls)accountBalance_lst[1]).AccountBalanceTotal; 
+0

ありがとう、これは私が探しているものです。 –

0

var accountBalance_lst = new List<accountBalance_cls>(); 

List<object> accountBalance_lst = new List<object>(); 

はなぜこれをしないでもないと、あなたは、いくつかの次のようなキャストを行うことができます

あなたが望むようにリストオブジェクトを使用できるようにするには:

関連する問題