Listview项上下移动 [英] Listview items moves up and down

查看:85
本文介绍了Listview项上下移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有列表视图项,它包含约10个项,我有2个按钮,例如上下.我们假设选择了listview的第一项,当我单击向下按钮时,它将转到第二个位置,而当我单击向上按钮时,它将移至上侧.
这样,在单击按钮的同时文件可以上下移动.

将Windows应用程序与c#代码一起使用.

问候
Vasanth

I have list view items, it contains some 10 items, I have 2 buttons like up and down. We assuming the listview first item is selected, when i click the down button it will goes to second position, same time when i click the up button it will moves to upside.
Like that way the files are moves up and down while click the button.

Using Windows Application with c# code.

Regards
Vasanth

推荐答案

使用系统;
使用System.Collections;
使用System.Configuration;
使用System.Data;
使用System.Linq;
使用System.Web;
使用System.Web.Security;
使用System.Web.UI;
使用System.Web.UI.HtmlControls;
使用System.Web.UI.WebControls;
使用System.Web.UI.WebControls.WebParts;
使用System.Xml.Linq;

公共局部类r2:System.Web.UI.Page
{
受保护的void Page_Load(对象发送者,EventArgs e){
if(!IsPostBack)
BindData();
}
受保护的void MoveRight(object sender,EventArgs e){
while(uxListBox1.Items.Count> 0&& uxListBox1.SelectedItem!= null){
ListItem selectedItem = uxListBox1.SelectedItem;
selectedItem.Selected = false;
uxListBox2.Items.Add(selectedItem);
uxListBox1.Items.Remove(selectedItem);
}
}
受保护的void MoveLeft(object sender,EventArgs e){
while(uxListBox2.Items.Count> 0&& uxListBox2.SelectedItem!= null){
ListItem selectedItem = uxListBox2.SelectedItem;
selectedItem.Selected = false;
uxListBox1.Items.Add(selectedItem);
uxListBox2.Items.Remove(selectedItem);
}
}
私有void BindData(){
uxListBox1.Items.Add(new ListItem("test1","test1")));
uxListBox1.Items.Add(new ListItem("test2","test2")));
uxListBox1.Items.Add(new ListItem("test3","test3")));
}
}

.aspx

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class r2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e) {
if(!IsPostBack)
BindData();
}
protected void MoveRight(object sender, EventArgs e) {
while(uxListBox1.Items.Count > 0 && uxListBox1.SelectedItem != null) {
ListItem selectedItem = uxListBox1.SelectedItem;
selectedItem.Selected = false;
uxListBox2.Items.Add(selectedItem);
uxListBox1.Items.Remove(selectedItem);
}
}
protected void MoveLeft(object sender, EventArgs e) {
while(uxListBox2.Items.Count > 0 && uxListBox2.SelectedItem != null) {
ListItem selectedItem = uxListBox2.SelectedItem;
selectedItem.Selected = false;
uxListBox1.Items.Add(selectedItem);
uxListBox2.Items.Remove(selectedItem);
}
}
private void BindData() {
uxListBox1.Items.Add(new ListItem("test1", "test1"));
uxListBox1.Items.Add(new ListItem("test2", "test2"));
uxListBox1.Items.Add(new ListItem("test3", "test3"));
}
}

.aspx

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ListBox ID="uxListBox1" runat="server" SelectionMode="multiple" />
        <asp:Button id="uxRightBtn" runat="server" OnClick="MoveRight" Text=" > " />
        <asp:Button id="uxLeftBtn" runat="server" OnClick="MoveLeft" Text=" < " />
        <asp:ListBox ID="uxListBox2" runat="server" SelectionMode="multiple" />
    </div>
    </form>
</body>
</html>


这篇关于Listview项上下移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆