/// <summary>
/// 上下移动 ListBox 内的项。
/// </summary>
/// by:范庆韬 2009-6-8,适用于 winform
/// <param name="listbox">控件名 ListBox</param>
/// <param name="type"> 0- 向上 1-向下</param>
/// <returns>int 0-成功 1-到顶了 2-到底了 3-要选择一项。</returns>
private int ListBox_UpNext(ListBox listbox, int type)
{
int returnstr = 0;
int list_count = listbox.SelectedItems.Count;
if (list_count == 1)
{
int _index = listbox.SelectedIndex; //取出选中的信息
int up_index = _index - 1; //根据选中的行,获取上一个项的信息
if (type == 1) up_index = _index + 1;
if (up_index < 0)
{
returnstr = 1; //返回值,到顶了。
up_index = 0;
MessageBox.Show("已经是第一项了!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
if (up_index > listbox.Items.Count - 1)
{
returnstr = 2; //返回值,到底了。
up_index = listbox.Items.Count - 1;
MessageBox.Show("已经是最后一项了!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
if (returnstr == 0)
{
string up_text = listbox.Items[up_index].ToString(); //计算出要操作的那一项的下一项。(向上的就出去前一项的内容,向下的就取出下一项的内容。)
listbox.Items.RemoveAt(up_index); //删除它
listbox.Items.Insert(_index, up_text); //在删除后的项列表的指定位置添加一个新的项,组合原来的项列表内容,组合后即为新顺序。
}
}
else
{
returnstr = 3;
MessageBox.Show("请选择一项移动。", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
return returnstr;
}
//使用样本。
ListBox_UpNext(listBox1, 0);
没有合适的资源?快使用搜索试试~ 我知道了~
上下移动ListBox内的项winform
共1个文件
txt:1个
1星 需积分: 10 34 下载量 196 浏览量
2009-06-15
19:23:51
上传
评论
收藏 943B RAR 举报
温馨提示
上下移动ListBox内的项 winform 程序,适合新手。 共享我的资源。
资源推荐
资源详情
资源评论
收起资源包目录
ListBox内的项winform .rar (1个子文件)
2 上下移动 ListBox 内的项 .txt 2KB
共 1 条
- 1
资源评论
- zhang_hong9992014-11-18不是我想要的。
fanlose2
- 粉丝: 3
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功