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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

checked listBox 1
remove selected item 1
remove from listBox 3
sum 4
ckecked listbox 4
listbox search 1
array list 15
print picture 2

Back
Top