作者:手机用户2502863963 | 来源:互联网 | 2023-09-23 11:53
ImadeanextensionmethodtoswapplacesoftwoitemsinaCheckedListBox.Themethodisputinas
I made an extension method to swap places of two items in a CheckedListBox. The method is put in a static Utilities class. The problem is that the CheckState doesn't travel. So if I move a checked item up in the list, the checkbox state will stay and the moved item will take over the CheckState from the item it's replacing.
我做了一个扩展方法来交换CheckedListBox中两个项目的位置。该方法放在静态Utilities类中。问题是CheckState不会移动。因此,如果我在列表中移动已检查的项目,则复选框状态将保留,移动的项目将从其替换的项目接管CheckState。
My code looks like this:
我的代码如下所示:
public static System.Windows.Forms.CheckedListBox.ObjectCollection Swap(this System.Windows.Forms.CheckedListBox.ObjectCollection lstBoxItems, int indexA, int indexB)
{
if (indexB > -1 && indexB
What I want is something like this (which doesn't work obviously)
我想要的是这样的东西(显然不起作用)
public static System.Windows.Forms.CheckedListBox.ObjectCollection Swap(this System.Windows.Forms.CheckedListBox.ObjectCollection lstBoxItems, int indexA, int indexB)
{
if (indexB > -1 && indexB
The code is simply called like this
代码就像这样简单地调用
myCheckedListBox.Items.Swap(selectedIndex, targetIndex);
2 个解决方案