【发布时间】:2009-01-04 00:09:01
【问题描述】:
下面的代码将列表框中的选定项向下移动到列表框中的下一项,但如果选定项被选中,它将取消选中。我怎样才能防止这种情况发生?
private void buttonMoveDown_Click(object sender, EventArgs e)
{
int iIndex = checkedListBox1.SelectedIndex;
if (iIndex == -1)
{
return;
}
moveListboxItem(checkedListBox1, iIndex, iIndex + 1);
}
谢谢
moveListboxItem的代码如下:
private void moveListboxItem(CheckedListBox ctl, int fromIndex,int toIndex)
{
if(fromIndex == toIndex)
{
return;
}
if(fromIndex < 0 )
{
fromIndex = ctl.SelectedIndex;
}
if(toIndex < 0 || toIndex > ctl.Items.Count - 1)
{
return;
}
object data = ctl.Items[fromIndex];
ctl.Items.RemoveAt(fromIndex);
ctl.Items.Insert(toIndex, data);
ctl.SelectedIndex = toIndex;
}
【问题讨论】:
-
您需要发布 moveListBoxItem 的来源以便我们能够提供帮助
标签: c# winforms listbox checkedlistbox