On Thu, 13 Apr 2006 12:31:16 +0200, "Hrvoje Voda" <hr*********@luatech.com>
wrote:
How to move up and down a selected item in listcheckedBox?
Hrcko
// paste this code in a new windows form containing a list box
// and two buttons
private void TestDialog_Load(object sender, EventArgs e)
{
string item = "Item";
for (int i = 0; i < 10; i++)
{
clb1.Items.Add(item + i.ToString());
}
}
private void upButton_Click(object sender, EventArgs e)
{
if (clb1.SelectedIndex > 0 )
{
int ndx = clb1.SelectedIndex;
string item = (string)clb1.SelectedItem;
clb1.Items.RemoveAt(ndx);
clb1.Items.Insert(ndx - 1, item);
clb1.SelectedIndex = ndx - 1;
}
}
private void downButton_Click(object sender, EventArgs e)
{
if (clb1.SelectedIndex < clb1.Items.Count - 1)
{
int ndx = clb1.SelectedIndex;
string item = (string)clb1.SelectedItem;
clb1.Items.RemoveAt(ndx);
clb1.Items.Insert(ndx + 1, item);
clb1.SelectedIndex = ndx + 1;
}
}
Good luck with your project,
Otis Mukinfus
http://www.arltex.com http://www.tomchilders.com