在C#中实现listbox的项上下移动(winform) 标准
|
--------------------------------------------------------------------------------------------------------------------------
//上移节点
private void btnUP_Click(object sender, EventArgs e)
{
int lbxLength = this.listBoxMenu.Items.Count;//listbox的长度
int iselect = this.listBoxMenu.SelectedIndex;//listbox选择的索引
if (lbxLength > iselect && iselect>0)
{
object oTempItem = this.listBoxMenu.SelectedItem;
this.listBoxMenu.Items.RemoveAt(iselect);
this.listBoxMenu.Items.Insert(iselect - 1, oTempItem);
this.listBoxMenu.SelectedIndex = iselect - 1;
}
}
//下移节点
private void btnDown_Click(object sender, EventArgs e)
{
int lbxLength = this.listBoxMenu.Items.Count;//listbox的长度
int iselect = this.listBoxMenu.SelectedIndex;//listbox选择的索引
if (lbxLength > iselect && iselect<lbxLength-1)
{
object oTempItem = this.listBoxMenu.SelectedItem;
this.listBoxMenu.Items.RemoveAt(iselect);
this.listBoxMenu.Items.Insert(iselect + 1, oTempItem);
this.listBoxMenu.SelectedIndex = iselect + 1;
}
}
原文链接:http://blog.csdn.net/maji9370/article/details/4294032
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GHGD.BLL;
namespace GHGD.UI
{
public partial class Form1 : Form
{
FrmDic_BLL frmDic_BLL = new FrmDic_BLL();
int strID = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//ListBox lst_frmDic_Type_Property = new ListBox();
//lst_frmDic_Type_Property.Items.Add("1");
//lst_frmDic_Type_Property.Items.Add("2");
//lst_frmDic_Type_Property.Items.Add("3");
//lst_frmDic_Type_Property.Items.Add("4");
//lst_frmDic_Type_Property.Items.Add("5");
DataSet dsFrmDic = frmDic_BLL.FrmDic_Dic_GetInfo();
lst_frmDic_Type.DataSource = dsFrmDic.Tables[0];
lst_frmDic_Type.DisplayMember = "DICType";
lst_frmDic_Type.ValueMember = "ID";
//for (int i = 0; i < 10; i++)
// lst_frmDic_Type_Property.Items.Add(i + 1);
}
private void lst_frmDic_Type_SelectedValueChanged(object sender, EventArgs e)
{
string strLstDicType = lst_frmDic_Type.Text;
FrmDicTypePropertyOnLoad(strLstDicType);
}
private void FrmDicTypePropertyOnLoad(string strLstDicType)
{
DataSet dsFrmDicTypeProperty = frmDic_BLL.FrmDic_Dic_GetInfo_Type(strLstDicType);
lst_frmDic_Type_Property.DataSource = dsFrmDicTypeProperty.Tables[0];
lst_frmDic_Type_Property.DisplayMember = "DICName";
lst_frmDic_Type_Property.ValueMember = "ID";
}
private void lst_frmDic_Type_Porperty_SelectedIndexChanged(object sender, EventArgs e)
{
string strLstDicTypeProperty = lst_frmDic_Type_Property.Text;
txt_frmDicTypePorperty_word.Text = strLstDicTypeProperty;
DataSet ds = frmDic_BLL.FrmDic_Dic_GetTypeProperty_ID(strLstDicTypeProperty);
strID = Convert.ToInt32(ds.Tables[0].Rows[0]["ID"]);
}
private void btn_frmDicType_MoveUp_Click(object sender, EventArgs e)
{
int position = lst_frmDic_Type_Property.SelectedIndex;
string value = lst_frmDic_Type_Property.SelectedItem.ToString();
MessageBox.Show("position: " + position + " _ " + "value: " + value);
if (position == 0)
{
MessageBox.Show("已在当前最顶端,无法再移动...");
return;
}
else
{
lst_frmDic_Type_Property.Items.RemoveAt(position);
lst_frmDic_Type_Property.Items.Insert(position - 1, value);
}
lst_frmDic_Type_Property.SetSelected(position - 1, true);
}
private void btn_frmDicType_MoveDown_Click(object sender, EventArgs e)
{
int position = lst_frmDic_Type_Property.SelectedIndex;
string value = lst_frmDic_Type_Property.SelectedItem.ToString();
if (position == lst_frmDic_Type_Property.Items.Count - 1)
{
MessageBox.Show("已在当前最底端,无法再移动...");
return;
}
else
{
lst_frmDic_Type_Property.Items.RemoveAt(position);
lst_frmDic_Type_Property.Items.Insert(position + 1, value);
}
lst_frmDic_Type_Property.SetSelected(position + 1, true);
}
}
}
=====================================================
在C#中实现listbox的项上下移动(winform) 标准的更多相关文章
- WPF 显示文件列表中使用 ListBox 变到ListView 最后使用DataGrid
WPF 显示文件列表中使用 ListBox 变到ListView 最后使用DataGrid 故事背景: 需要检索某目录下文件,并列出来,提供选择和其他功能. 第一版需求: 列出文件供选择即可,代码如下 ...
- asp.net中的ListBox控件添加双击事件
问题:在Aspx页里的ListBox A中添加双击事件,将选中项添加到另一个ListBox B中,双击ListBox B中的选中项,删除当前选中项 页面: <asp:ListBox ID=&qu ...
- "不能在 DropDownList 中选择多个项。"其解决办法及补充
探讨C#.NET下DropDownList的一个有趣的bug及其解决办法 摘要: 本文就C#.Net 环境下Web开发中经常使用的DropDownList控件的SelectedIndex属性进行了详细 ...
- 不能在DropDownList 中选择多个项
在绑定DropDownList时如果出现多次绑定,会出错以下错误: “不能在DropDownList 中选择多个项” 经了解,只需要在选中值是清空选择即可:xxDropDownList.ClearSe ...
- Windows Phone 7 ListBox 列表项渐显加载动画学习笔记
在wp7程序中,当程序功能越来越复杂时,性能问题是我们不得不考虑的一个问题.在聊天列表中,如果聊天项过多,而且项目UI组件足够复杂时, 我们不得不想尽办法让UI尽快加载.所以有一种可行的方案,就是像Q ...
- php 查找数组中是否存在某项,并返回指定的字符串,可用于检查复选,单选等
/** * 查找数组中是否存在某项,并返回指定的字符串,可用于检查复选,单选等 * @param $id * @param $ids * @param string $returnstr * @ret ...
- .net中不能在DropDownList中选中多个项的解决方法
页面中放有多个DropDownList,点击修改时候,需要根据值来设置两个DropDownList的选中项,当值为空时则需要选中默认值. 页面报错:不能在DropDownList中选中多个项. 直接粘 ...
- WPF中反转3D列表项
原文:WPF中反转3D列表项 WPF中反转3D列表项 周银辉记得在苹果电脑中有一个很酷的 ...
- Win10系列:JavaScript 项目模板中的文件和项模板文件
通过上面内容的学习,相信读者已经对各种项目模板和项模板有了大致的了解,本节将进一步介绍项目模板中默认包含的项目文件以及项模板文件,首先讲解这些文件中的初始内容以及作用,然后介绍在一个页面中如何添加控件 ...
随机推荐
- Spring框架系列(五)--面向切面AOP
背景: 当需要为多个不具有继承关系的对象引入一个公共行为,例如日志.权限验证.事务等功能时,如果使用OOP,需要为每个对象引入这些公共 行为.会产生大量重复代码,并且不利用维护.AOP就是为了解决这个 ...
- 怎么让Eclipse对html和js代码自动提示
使用eclipse自带的插件,无需另外安装插件,具体步骤如下1.打开eclipse→Windows→Preferences→Java→Editor→Content Assist修改Auto Activ ...
- 11Java Server Pages 动作
Java Server Pages 动作 JSP标准动作 分类 JSP标准动作 存取JavaBean相关 <jsp:useBean> <jsp:setProperty> < ...
- 牛客多校Round 3
Solved:2 rank:306 跑路场..... A.PACM team 简单背包记录路径都写挂 退役算了 #include <bits/stdc++.h> using namespa ...
- How To:分析ORACLE监听日志中的IP信息
有时候需要分析出ORACLE日志监听中的IP信息,分享一个组合命令,Linux的shell下运行正常. grep "HOST=.*establish.*\* 0" listener ...
- java 十三周总结
- 07 Python编码问题
17) 编码 18) Python3的执行过程 19) 常见编码错误原因 20) 后附一部分编码详细信息(个人总结,有误望指正) 想了解Python3的编码更细致的讲解请参考大王的文章 http:// ...
- react入门----(this.state/表单/Ajax)
1.this.state 组件免不了要与用户互动,React 的一大创新,就是将组件看成是一个状态机,一开始有一个初始状态,然后用户互动,导致状态变化,从而触发重新渲染 UI var TestStat ...
- hdu 1754 I Hate It(线段树水题)
>>点击进入原题测试<< 思路:线段树水题,可以手敲 #include<string> #include<iostream> #include<a ...
- 常量Constant
常量通常指的是一个固定的值,例如:1.2.3.’a’.’b’.true.false.”helloWorld”等. 在Java语言中,主要是利用关键字final来定义一个常量. 常量一旦被初始化后不能再 ...