Click here to Skip to main content
15,901,853 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hii ,

I have list items which are coming from database. I want to remove particular item from list item from list before binding that list object to datagrid control. If i go fore removeat (index) option in future i might have problem , because if some databse changes occurs and order changes it will afttect to gridview . So can i remove an item using its name present in list ?
Posted
Comments
Harshil_Raval 17-Sep-13 2:39am    
Yes, just go loop through your list, and find list item and delete it..
V.Lorz 17-Sep-13 3:13am    
What type of list are you using for holding the values? What kind of problem you say you'll have in the future?
Torakami 17-Sep-13 3:28am    
I am using object list type , its coming to class objects from sp and function is returning this class objecti and i am storing it to list object.

problem is that i want to permantly skip perticular item from list .. but in case if i use index an in future if order of that row changes in databse table .. my index value will be different and it will skip some other item
V.Lorz 17-Sep-13 3:40am    
Ok, if you're working with databases most surely you've added each table one column with autogenerated unique indexes. This is normally done for you by most database table editors. The value for this column is automatically generated by the database engine on each new row insertion.

That solves your problem. When you recover your data you somehow keep that index too so you can use it for uniquely identifying your rows (referenced by your objects in your list) in your row updates/deletes/etc.
Torakami 17-Sep-13 3:46am    
what are you saying >??? i am not at all using any index from database column ... i am using index in list item

1 solution

You can use this lamda expression

yourlist.RemoveAll(p=>p.propertyname == "valuetocheck");
 
Share this answer
 
Comments
Torakami 17-Sep-13 2:58am    
i tried this but if i use somthing of this

lstMenu.removeall(p=>p.menuname.tolower()=="company objectives");

its throwing me an error saying company is not present .. as it taking only part company not complete company objectives . i got this when i added a watch on this
gajendra_kshatriya 18-Sep-13 1:15am    
Can you paste your some code snippet so i can suggest better?
Faisalabadians 19-Sep-13 4:32am    
removing an item from a list in C# will not change all remaining items index?

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