C# - How To Add And Remove Item From ListBox And Move Items Up And Down
In This C# Tutorial We Will See How To Insert Using TextBox , ComboBox And Delete Item From ListBox And Moving Item Up N Down Using CSharp Programming Language.
Project Source Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Csharp_And_MySQL
{
public partial class Csharp_ListBox : Form
{
public Csharp_ListBox()
{
InitializeComponent();
}
private void BTN_ADD_Click(object sender, EventArgs e)
{
// add item to listbox from textbox
listBox1.Items.Add(textBox1.Text);
// add item to listbox from combobox
listBox1.Items.Add(comboBox1.SelectedItem.ToString());
}
// button move selected listbox item up
private void BTN_UP_Click(object sender, EventArgs e)
{
int i = listBox1.SelectedIndex;
string item = listBox1.SelectedItem.ToString();
if(i > 0)
{
listBox1.Items.RemoveAt(i);
listBox1.Items.Insert(i - 1, item);
listBox1.SetSelected(i - 1, true);
}
}
// button move selected listbox item down
private void BTN_DOWN_Click(object sender, EventArgs e)
{
int i = listBox1.SelectedIndex;
string item = listBox1.SelectedItem.ToString();
if (i < listBox1.Items.Count -1 )
{
listBox1.Items.RemoveAt(i);
listBox1.Items.Insert(i + 1, item);
listBox1.SetSelected(i + 1, true);
}
}
}
}
///////////////OUTPUT:
Download Projects Source Code
3 comments
commentsFantastic java source codes. I tried to purchase java inventory source code from sellfy.com but the platform doesnt support Ghana from the country list.Any help?
Replysiuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
Replymerci beaucoup de tout se que vous faites pour nous
Reply