Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
580
Clone ValueList and remove some items
posted

I have two value lists when first one is selected, the other one is loaded without selected element. When I try to remove selectedListItem nothing happens? It looks like list doesn’t recognize that it contains that item?

 

private void laodList(UltraGridRow row,  ValueListItem selectedListItem)

{           

ValueList elementList = (ValueList)row.Cells["Element"].ValueListResolved;                             

 

//clone list

ValueList minMaxList = elementList.Clone();

        

//remove selected element

minMaxList.ValueListItems.Remove(selectedListItem);

                       

row.Cells["MinElement"].ValueList = minMaxList;

           

}

  • 469350
    Offline posted

    minMaxList.ValueListItems.Remove(selectedListItem);

    This code doesn't work because selectedListItem is a ValueListItem in the original list. It does not get removed, because it doesn't exist in the cloned list. The cloned list contains a cloned item with the same values as selectedListItem, but it's not the same item.

  • 580
    Verified Answer
    posted

    I had to find it firts and then delete worked.

    ValueListItem

     

     

    itemToRemove = minMaxList.FindByDataValue(selectedValue);

    if ( itemToRemove != null )

    minMaxList.ValueListItems.Remove(itemToRemove);