ボタンクリックイベントで現在のobservablecollectionデータをリストに入れたいと思います。ベローはC#のコードですが、エラーが発生します:オブジェクト参照がオブジェクトのインスタンスに設定されていません。observablecollectionをリストに入れる方法
ObservableCollection<CheckInData> _CheckInCollection = new ObservableCollection<CheckInData>();
public ObservableCollection<CheckInData> CheckInCollection
{
get { return _CheckInCollection; }
}
public class CheckInData
{
public string RoomNumber { get; set; }
public decimal Price { get; set; }
public string Currecny { get; set; }
public decimal Discount { get; set; }
public string CheckOut { get; set; }
public int TotalDay { get; set; }
public decimal TotalPrice { get; set; }
public int CheckOutYear { get; set; }
public int CheckOutMonth { get; set; }
public int CheckOutDay { get; set; }
public Boolean IncToday { get; set; }
}
private void btnPrintInvoice_Click(object sender, RoutedEventArgs e)
{
DataToExcel.Invoice inv = new DataToExcel.Invoice();
inv._BilledTo = Guest[0];
foreach (CheckInData coll in _CheckInCollection)
{
for (int i = 0; i < _CheckInCollection.Count; i++)
{
inv._RoomPrice.Add(coll.RoomNumber[i].ToString());
}
}
}
この例外はどの回線で通知されますか? – colithium
inv._RoomPrice.Add(coll.RoomNumber [i] .ToString()); –