Hello,
How to move up and down in listbox items
regards
sreejsh
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Anurag SarkarRank #1,049 · 1.8K reputationPosted Jan 15, 2013, 3:27 AM EST
Please check this and tell further if anything else is required.
Satyapriya NayakRank #47 · 31.5K reputationPosted Jan 15, 2013, 5:30 AM EST
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Move_items_from_one_listbox_other
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
listBox1.Items.Add("Raj");
listBox1.Items.Add("Ravi");
listBox1.Items.Add("Rahul");
listBox1.Items.Add("Raju");
listBox1.Items.Add("Rohit");
listBox1.Items.Add("Rajesh");
}
private void button1_Click(object sender, EventArgs e)
{
listBox2.Items.Add(listBox1.SelectedItem);
int i = 0;
i = listBox1.SelectedIndex;
listBox1.Items.RemoveAt(i);
}
private void button2_Click(object sender, EventArgs e)
{
listBox1.Items.Add(listBox2.SelectedItem);
int i = 0;
i = listBox2.SelectedIndex;
listBox2.Items.RemoveAt(i);
}
private void button3_Click(object sender, EventArgs e)
{
int j = 0;
for (j = 0; j <= listBox1.Items.Count - 1; j++)
{
listBox2.Items.Add(listBox1.Items[j]);
}
listBox1.Items.Clear();
}
private void button4_Click(object sender, EventArgs e)
{
int j = 0;
for (j = 0; j <= listBox2.Items.Count - 1; j++)
{
listBox1.Items.Add(listBox2.Items[j]);
}
listBox2.Items.Clear();
}
}
}
Jignesh TrivediRank #16 · 50.3K reputationPosted Jan 15, 2013, 6:18 PM EST
Are you using desktop or web base application development?
For desktop please refer
http://www.codeproject.com/Articles/24682/Moving-listbox-items
for web base
Jquery or Java script is best option to perform same
please refer
http://codes.codedigest.com/CodeDigest/134-Move-List-Items-Up-and-Down-Using-jQuery-in-ASP-Net-ListBox-control.aspx
hope this will help you.