C#WinFormListBox数据项的上下移动
2015-09-25 20:45
399 查看
private void button1_Click(object sender, EventArgs e)
{
int lbxLength = this.listBox1.Items.Count;//listbox的长度
int iselect = this.listBox1.SelectedIndex;//listbox选择的索引
if (lbxLength > iselect && iselect > 0)
{
object oTempItem = this.listBox1.SelectedItem;
this.listBox1.Items.RemoveAt(iselect);
this.listBox1.Items.Insert(iselect - 1, oTempItem);
this.listBox1.SelectedIndex = iselect - 1;
}
}
private void button2_Click(object sender, EventArgs e)
{
int lbxLength = this.listBox1.Items.Count;//listbox的长度
int iselect = this.listBox1.SelectedIndex;//listbox选择的索引
if (iselect <lbxLength-1)
{
object oTempItem = this.listBox1.SelectedItem;
this.listBox1.Items.RemoveAt(iselect);
this.listBox1.Items.Insert(iselect + 1, oTempItem);
this.listBox1.SelectedIndex = iselect + 1;
}
}
{
int lbxLength = this.listBox1.Items.Count;//listbox的长度
int iselect = this.listBox1.SelectedIndex;//listbox选择的索引
if (lbxLength > iselect && iselect > 0)
{
object oTempItem = this.listBox1.SelectedItem;
this.listBox1.Items.RemoveAt(iselect);
this.listBox1.Items.Insert(iselect - 1, oTempItem);
this.listBox1.SelectedIndex = iselect - 1;
}
}
private void button2_Click(object sender, EventArgs e)
{
int lbxLength = this.listBox1.Items.Count;//listbox的长度
int iselect = this.listBox1.SelectedIndex;//listbox选择的索引
if (iselect <lbxLength-1)
{
object oTempItem = this.listBox1.SelectedItem;
this.listBox1.Items.RemoveAt(iselect);
this.listBox1.Items.Insert(iselect + 1, oTempItem);
this.listBox1.SelectedIndex = iselect + 1;
}
}
相关文章推荐
- C#编写NotifyIcon 将窗口最小化到托盘
- C#将string转换为十六进制
- 【转载】C#验证控件的使用方法(RegularExpressionValidator)的使用
- C#中Winform程序调用WebService服务
- C#中Winform程序调用WebService服务
- C# 将短时间格式变长正常时间格式
- C# 如何调用可执行程序传参
- C# .net设置系统音量
- (转)C#.NET如何不序列化字段、属性
- c#中DllImport的用法
- Code First的migration应用
- C#实现多线程
- C# DES进行加解密
- C# UDP 接收客户端指令并发送数据
- C# 托管内存与非托管内存之间的转换
- C#命名规范(简述)
- WinForm(C#)中跨线程访问控件的解决方法
- 【转】c#数组定义
- C# form程序读取console 程序的控制台信息
- 【转】C#调用Windows图片和传真查看器打开图片