[英]c# WPF get value from a List<> that is binded to a class object
How to get value from a list that is binded to a class object? 如何从绑定到类对象的列表中获取值? I have a class and a List of that class.
我有一个类和该类的列表。 im adding to list like this
即时添加到列表中
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();
}
this is my class 这是我的班级
public class accountBalanace_cls
{
public string accountBalanceTotal { get; set; }
public string accountBalanceAmount { get; set; }
public string accountBalanceTransaction { get; set; }
public string accountBalanceDate { get; set; }
}
and this is my declaration of List 这是我对List的声明
List<object> accountBalance_lst = new List<object>();
What I want to do is something like this I hope you'll understand what i'm trying to accomplish here 我想做的是这样的事情,我希望你能理解我在这里想要完成的事情
int total = accountBalance_lst[1].AccountBalanceTotal;
The accountBalance_lst
is of type List<object>
it doesn't contains definition for AccountBalanceTotal
. accountBalance_lst
的类型为List<object>
它不包含AccountBalanceTotal
定义。 if doesn't have any specific reason for List<object>
then make it as List<accountBalanace_cls>
instead. 如果
List<object>
没有任何特定原因,则将其设为List<accountBalanace_cls>
。 Or else you can do some casting like the following: 或者你可以像下面这样做一些演员:
int total = ((accountBalanace_cls)accountBalance_lst[1]).AccountBalanceTotal;
Not sure I fully understand your question, but instead of doing this: 不确定我完全理解你的问题,但不是这样做:
List<object> accountBalance_lst = new List<object>();
Why not do this: 为什么不这样做:
var accountBalance_lst = new List<accountBalance_cls>();
So that you can do you can use the list objects like you wanted: 这样你就可以使用你想要的列表对象:
int total = accountBalance_lst[1].AccountBalanceTotal;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.