vs2005空间之ListBox有用的代码-- //向上下移动
2006-08-24 00:08
267 查看
//向上下移动一条 事件
if (((Button)sender).CommandName == "up" && ListBox6.SelectedIndex > 0 || ((Button)sender).CommandName == "down" && ListBox6.SelectedIndex < ListBox6.Items.Count - 1)
{ //判断传来的命令名必须是 up并且所选条目的索引必须大于0 或者 down并且所选条目必须小于最大项
int index;//为了减少代码,这里做一个对变量的判断,以后就直接调用变量,
if (((Button)sender).CommandName == "up")
{
index = -1;//以后的索引本来就是在当前的条目上加一或者减,所以这个方法很不错
}
else
{
index = 1;
}
ListItem lt = new ListItem(ListBox6.SelectedItem.Text,ListBox6.SelectedValue);//将当前条目的文本以及值都保存到一个临时变量里面
ListBox6.Items [ListBox6.SelectedIndex].Text = ListBox6.Items[ListBox6.SelectedIndex + index]. Text;//被选中项的值等于上一条或者下一条的值
ListBox6.Items [ListBox6.SelectedIndex].Value = ListBox6.Items[ListBox6.SelectedIndex + index]. Value;//被选中项的值等于上一条或者下一条的值
ListBox6.Items[ListBox6.SelectedIndex + index].Text = lt.Text;//把被选中项的上一条或者下一条的值用临时变量中的取代
ListBox6.Items[ListBox6.SelectedIndex + index].Value = lt.Value;//把被选中项的上一条或者下一条的值用临时变量中的取代
ListBox6.SelectedIndex = ListBox6.SelectedIndex + index;//把鼠标指针放到移动后的那条上
}
if (((Button)sender).CommandName == "up" && ListBox6.SelectedIndex > 0 || ((Button)sender).CommandName == "down" && ListBox6.SelectedIndex < ListBox6.Items.Count - 1)
{ //判断传来的命令名必须是 up并且所选条目的索引必须大于0 或者 down并且所选条目必须小于最大项
int index;//为了减少代码,这里做一个对变量的判断,以后就直接调用变量,
if (((Button)sender).CommandName == "up")
{
index = -1;//以后的索引本来就是在当前的条目上加一或者减,所以这个方法很不错
}
else
{
index = 1;
}
ListItem lt = new ListItem(ListBox6.SelectedItem.Text,ListBox6.SelectedValue);//将当前条目的文本以及值都保存到一个临时变量里面
ListBox6.Items [ListBox6.SelectedIndex].Text = ListBox6.Items[ListBox6.SelectedIndex + index]. Text;//被选中项的值等于上一条或者下一条的值
ListBox6.Items [ListBox6.SelectedIndex].Value = ListBox6.Items[ListBox6.SelectedIndex + index]. Value;//被选中项的值等于上一条或者下一条的值
ListBox6.Items[ListBox6.SelectedIndex + index].Text = lt.Text;//把被选中项的上一条或者下一条的值用临时变量中的取代
ListBox6.Items[ListBox6.SelectedIndex + index].Value = lt.Value;//把被选中项的上一条或者下一条的值用临时变量中的取代
ListBox6.SelectedIndex = ListBox6.SelectedIndex + index;//把鼠标指针放到移动后的那条上
}
相关文章推荐
- select下拉框的上下左右移动,多行排序等,很好的代码。大家有用就看看吧。
- vs2005制做左右上下移动的Listbox ( asp.net , C#)
- 成长手删代码40-listbox js操作上下左右移动.txt
- vs2005制做左右上下移动的Listbox ( asp.net , C#)
- jQuery实现table中的tr上下移动并保持序号不变的实例代码
- 将ListBox选中的项进行上下移动
- 文字来回上下移动或跳动的代码
- Jquery 关于table整行上下移动的代码
- .net C# listbox的上下移动,拖动排序,两个listbox相互拖动
- ASP.NET ListBox的使用与其上下移动方法
- [WinForm]ListBox的Item上下移动
- 设置整行代码上下移动 删除
- 【代码保留】WinForm ListBox上下移动选中项(扩展)
- jquery实现tr元素的上下移动示例代码
- JavaScript控制listbox列表框的项目上下移动的方法
- 文字来回上下移动或跳动的代码
- JS动态的把左边列表添加到右边的实现代码(可上下移动)
- jquery移动listbox的值原理及代码
- 在C#中实现listbox的项上下移动(winform) 标准
- JQuery ListBox间移动和ListBox内上下移动