How do I make a ListBox refresh its item text?

前端 未结 10 1995
后悔当初
后悔当初 2020-12-03 04:42

I\'m making an example for someone who hasn\'t yet realized that controls like ListBox don\'t have to contain strings; he had been storing formatted strings and

10条回答
  •  天涯浪人
    2020-12-03 05:08

    It's little bit unprofessional, but it works. I just removed and added the item (also selected it again). The list was sorted according to "displayed and changed" property so, again, was fine for me. The side effect is that additional event (index changed) is raised.

    if (objLstTypes.SelectedItem != null)
    {
     PublisherTypeDescriptor objType = (PublisherTypeDescriptor)objLstTypes.SelectedItem;
     objLstTypes.Items.Remove(objType);
     objLstTypes.Items.Add(objType);
     objLstTypes.SelectedItem = objType;
    }
    

提交回复
热议问题