Click here to Skip to main content
16,020,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello
I want to put observablecollection into the List<string> like this :
C#
List<string> test = new List<string>();
          foreach (CheckInData coll in CheckInCollection)
          {
              for (int i = 0; i < _CheckInCollection.Count; i++)
              {
               test.Add(coll.RoomNumber[i].ToString());
              }
              
          }

but its only put the first character of collection for example there is 2424 test content will be only 2.
Please help me anybody

This is my Collection:

C#
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; }
   }
Posted

1 solution

What do want to put in your List? The RoomNumber?

Maybe this will help you... not the best solution... but it is one ;)

List<string> test = new List<string>();
    foreach (CheckInData checkInData in CheckInCollection)
    {
        if (!test.Contains(checkInData.RoomNumber))
	     test.Add(checkInData.RoomNumber);
    }		
</string></string>



Renamed the variable coll into checkInData...
 
Share this answer
 
v3
Comments
lester555 27-Jul-11 8:22am    
When RoomNumber contains collection i want to put it another class List<string>
StM0n 27-Jul-11 8:31am    
Sorry for asking again. You would like to put the roomnumbers into the List?
lester555 27-Jul-11 8:33am    
yes i just want to copy all roomnumbers into list
lester555 27-Jul-11 8:44am    
no no noooooooooooooooooooo. its onlay adds The first value. For example if roomNumber contains 555 and 666 test value will be only 555. f*** all day long i trying this bullsh*t
StM0n 27-Jul-11 8:52am    
In your code it does, due the fact you're iterating over the characters in the roomnumber... but what you really want (if I get this right), is, putting all roomnumbers in your test-collection. Correct me, if I'm wrong.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900