moving selected item

  • Thread starter Thread starter Hrvoje Voda
  • Start date Start date
Hrvoje,

You change the CheckedListBox.SelectedIndex or CheckedListBox.SelectedItem
properties.
 
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
 
There is just one problem.
When i move a checked item a checkedstate is lost.
How can i prevent this from happening?
 
Back
Top