CheckedListBox에 두 항목의 위치를 바꾸는 확장 메서드를 만들었습니다. 이 메서드는 정적 유틸리티 클래스에 저장됩니다. 문제는 CheckState가 이동하지 않는다는 것입니다. 체크 된 항목을 목록에서 위로 이동하면 체크 상자 상태가 유지되고 이동 된 항목이 해당 항목에서 CheckState를 인계합니다.항목 가져 오기 정적 메서드로 CheckState
내 코드는 다음과 같습니다
public static System.Windows.Forms.CheckedListBox.ObjectCollection Swap(this System.Windows.Forms.CheckedListBox.ObjectCollection lstBoxItems, int indexA, int indexB)
{
if (indexB > -1 && indexB < lstBoxItems.Count - 1)
{
object tmpItem = lstBoxItems[indexA];
lstBoxItems[indexA] = lstBoxItems[indexB];
lstBoxItems[indexB] = tmpItem;
}
return lstBoxItems;
}
(분명히 작동하지 않습니다)이 같은
public static System.Windows.Forms.CheckedListBox.ObjectCollection Swap(this System.Windows.Forms.CheckedListBox.ObjectCollection lstBoxItems, int indexA, int indexB)
{
if (indexB > -1 && indexB < lstBoxItems.Count - 1)
{
object tmpItem = lstBoxItems[indexA];
System.Windows.Forms.CheckState state = tmpItem.CheckState;
lstBoxItems[indexA] = lstBoxItems[indexB];
lstBoxItems[indexB] = tmpItem;
}
return lstBoxItems;
}
코드는 단순히이
myCheckedListBox.Items.Swap(selectedIndex, targetIndex);
처럼라고는 내가 원하는입니다
감사합니다. 솔루션을보기 전에 몇 분만에 문제를 풀었습니다. 동일한 변수 이름과 구문을 사용했습니다 :-). 확인을위한 Thx! 그것을 upvote 받아들입니다. – Christoffer