Dynamically changing the text of items in a Winforms ComboBox

后端 未结 4 1948
野趣味
野趣味 2020-12-18 08:08

I have a Winforms ComboBox that contains instances of a custom class. When the items are first added to the Items collection of the ComboBox, the

4条回答
  •  被撕碎了的回忆
    2020-12-18 08:33

    I use this extension:

            /// 
            /// Recreates the items
            /// 
            public static void RefreshItems(this ComboBox cb)
            {
                var selectedIndex = cb.SelectedIndex;
                cb.SelectedIndex = -1;            
                MethodInfo dynMethod = cb.GetType().GetMethod("RefreshItems", BindingFlags.NonPublic | BindingFlags.Instance);
                dynMethod.Invoke(cb, null);
                cb.SelectedIndex = selectedIndex;
    
            }
    

提交回复
热议问题