Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi..
i am using List<Type>(Type is a class object which contains fields like id,name,price,quantity) in wpf. i want to edit a row in a list with selected id.
how can i do this?
thanks.
Posted

Your question is porrly word. Do you want to allow the user to edit the row in a listview, or do you want to change the value in the List<>?
 
Share this answer
 
Comments
niravsahayata 15-May-10 7:29am    
i want user to make change in List<>...
Find the item in the list with the desired ID and change the desired property for that item. There are a couple of ways you can find the item - iterating the list with a for loop, or using Linq. Personally, I think a for loop is more efficient, but a Linq statement requires less code.

for (int i = 0; i < myList.Count; i++)
{
    if (myList[i].ID == ID)
    {
        myList[i].myPropery = newValue;
        break;
    }
}


or with linq

var result = (from MyItem item in myList 
              where item.ID = ID
              select item);
result.myProperty = property;


Code provided above may need tweaking because I did it from memory. BTW, this is all very basic programming stuff. Maybe you should be more open to using google.
 
Share this answer
 

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