将项目移动到列表框时出现问题 [英] problem in moving item, listbox to listbox

查看:360
本文介绍了将项目移动到列表框时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在chsarp.net中将数据从一个列表框移动到另一个列表时遇到问题

请帮助我...................

i have problem to move data from one listbox to another in chsarp.net

please help me ...................

推荐答案

更多信息后,我提出以下解决方案:
After some more info, I present this solution:
void Initialize()
{
    listBox1.Items.AddRange(new object[]{"this", "is","some","data"});
    listBox1.SelectedIndexChanged += new EventHandler(OnSelectedIndexChanged);}

void OnSelectedIndexChanged(object sender, EventArgs e)
{
    ListBox lb = (ListBox)sender;
    if (lb.SelectedIndex == -1)
        return;
            
    listBox2.Items.Add(lb.SelectedItem);
    lb.Items.Remove(lb.SelectedItem);
    lb.SelectedIndex = -1;
}



好的,现在我知道这确实是一个拖放问题.
[尝试这篇文章].如果您在Google上搜索列表框拖放",它应该会弹出.



Ok, now I know that this really is a drag n''drop question.
[Try this article]. It should have popped up if your googled "listbox drag drop".


我仍然有问题,

我想通过单击将多个项目从一个列表框移动到另一个列表中


请帮助我
i still have problem,

i want to move multiple items from one listbox to another on single click


please help me


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Interchange/Swap List Items</title>
<script type="text/javascript">
function moveToRightOrLeft(side){
var listLeft=document.getElementById('selectLeft');
var listRight=document.getElementById('selectRight');

if(side==1){
if(listLeft.options.length==0){
alert('You have already moved all countries to Right');
return false;
}else{
var selectedCountry=listLeft.options.selectedIndex;

move(listRight,listLeft.options[selectedCountry].value,listLeft.options[selectedCountry].text);
listLeft.remove(selectedCountry);

if(listLeft.options.length>0){
listLeft.options[0].selected=true;
}
}
}else if(side==2){
if(listRight.options.length==0){
alert('You have already moved all countries to Left');
return false;
}else{
var selectedCountry=listRight.options.selectedIndex;

move(listLeft,listRight.options[selectedCountry].value,listRight.options[selectedCountry].text);
listRight.remove(selectedCountry);

if(listRight.options.length>0){
listRight.options[0].selected=true;
}
}
}
}

function move(listBoxTo,optionValue,optionDisplayText){
var newOption = document.createElement("option");
newOption.value = optionValue;
newOption.text = optionDisplayText;
listBoxTo.add(newOption, null);
return true;
}
</script>
</head>

<body><form id="form1" runat="server">
<div>
<ul>
<li><table border="0">
<tr>
<td colspan="4">Example 1:</td>
</tr>
<tr>
<td colspan="2">Available Countries </td>
<td colspan="2">Your Selection </td>
</tr>
<tr>
<td rowspan="3" align="right"><label>
<select name="selectLeft"  size="10" id="selectLeft">
<option value="AS" selected="selected">American Samoa</option>
<option value="AD">Andorra</option>
<option value="AO">Angola</option>
<option value="AI">Anguilla</option>
<option value="AQ">Antarctica</option>
<option value="AG">Antigua And Barbuda</option>
<option value="AR">Argentina</option>
<option value="AM">Armenia</option>
<option value="AW">Aruba</option>
<option value="AU">Australia</option>
<option value="AT">Austria</option>
</select>
</label></td>
<td align="left">&nbsp;</td>
<td align="left">&nbsp;</td>
<td rowspan="3" align="left">
<select name="selectRight"    size="10" id="selectRight">
<option value="AF" selected="selected">Afghanistan</option>
<option value="AX">&Atilde;&hellip;Land Islands</option>
<option value="AL">Albania</option>
<option value="DZ">Algeria</option>
</select></td>
</tr>
<tr>
<td align="left">&nbsp;</td>
<td align="left"><label>
<input name="btnRight" type="button" id="btnRight" value="&gt;&gt;" onClick="javascript:moveToRightOrLeft(1);">
</label></td>
</tr>
<tr>
<td align="left">&nbsp;</td>
<td align="left"><label>
<input name="btnLeft" type="button" id="btnLeft" value="&lt;&lt;" onClick="javascript:moveToRightOrLeft(2);">
</label></td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="left">&nbsp;</td>
<td align="left">&nbsp;</td>
<td align="left">&nbsp;</td>
</tr>
</table>
</li>
<li>
<div>

</div>
</li>
<li class="code_right"></li>
</ul>
</div> </form>


</body>
</html>



这篇关于将项目移动到列表框时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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