开发者

C#. WPF. observablecollection how to get current items

This is my collection :

ObservableCollection<CheckInData> _CheckInCollection = new ObservableCollection<CheckInData>();
public ObservableCollection<CheckInData> CheckInCollection
{
 开发者_如何学JAVA   get { return _CheckInCollection; }
}

public class CheckInData
{
    public string RoomNumber { get; set; }
    public string Price { get; set; }
    public string Currecny { get; set; }
    public string Discount { get; set; }
    public string CheckOut { get; set; }
    public string 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; }
    public string CheckIn { get; set; }
    public decimal MoneyRate { get; set; }
}

I have one class where i save export my collection this way:

foreach (CheckInData coll in CheckInCollection)
{
    var roomType = (from d in db.SelectRooms where d.roomnumber == coll.RoomNumber select d.roomtype).SingleOrDefault();
    inv._RoomType.Add(roomType.ToString());
    inv._RoomNumber.Add(coll.RoomNumber.ToString());
    inv._CheckIn.Add(coll.CheckIn);
    inv._CheckOut.Add(coll.CheckOut);
    inv._DayNight.Add(coll.TotalDay);
    inv._RoomPrice.Add(coll.Price);
    inv._Discount.Add(coll.Discount);
}

This code works perfectly. I have list view which is binding with this observable collection so my question is how i can insert into inv._RoomType, inv._RoomNumber... only that collection which(rows) are selected in listview. inv._RoomNumber.Add(coll.RoomNumber(listview selected items? ??)) Thanks


You need to add an IsSelected property to your CheckInData class and then bind to that from the ListView. You can then say

foreach (CheckInData coll in CheckInCollection.Where(s => s.IsSelected))
{
 ...


From your description, I guess you have to get all selected item from the ListView UI control.

If so, ListView provides two properties: ListView.SelectedItem or ListView.SelectedItems, depending on whether you enabled multi-selection.

Let's assume you'd like to multi-select these items. Then the following code will help you with your question:

foreach(var item in listView.SelectedItems) 
    YourClass.Insert(item as CheckInData);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜