Hi Chris,
As far as I understand, your goal is to rearrange the items by moving up/down a selected item through the
Items collection on every button click. In your code you're using the
Text property of RadListBoxItem which seems to change the position of the selected item, but you are not actually moving the item.
To achieve your goal I'll suggest the following approach:
private void btnUp_Click(object sender, EventArgs e) |
{ |
if (radListBox1.SelectedIndex > 0) |
{ |
int index = radListBox1.SelectedIndex; |
RadListBoxItem current = radListBox1.SelectedItem as RadListBoxItem; |
radListBox1.Items.Remove(current); |
radListBox1.Items.Insert(index - 1, current); |
radListBox1.SelectedIndex = index - 1; |
} |
} |
|
private void btnDown_Click(object sender, EventArgs e) |
{ |
if ((radListBox1.SelectedIndex > -1) && (radListBox1.SelectedIndex < radListBox1.Items.Count - 1)) |
{ |
int index = radListBox1.SelectedIndex; |
RadListBoxItem current = radListBox1.SelectedItem as RadListBoxItem; |
radListBox1.Items.Remove(current); |
radListBox1.Items.Insert(index + 1, current); |
radListBox1.SelectedIndex = index + 1; |
} |
} |
I hope this helps!
Sincerely yours,
Georgi
the Telerik team