Ordering an asp.net Listbox
-
hi Looking for a bit of help. I have an asp.net listbox. I am wanting to manually be able to order the box by clicking a button. got everything set up but I keep getting an error saying that I can't have multiple selections on the list box when it is set as a single selection. I don't really know where I am going wrong so if anyone can help me I would most appreciate it. My code for the button click is as follows.
Protected Sub btOrderElementUp_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btOrderElementUp.Click If ltbOrderByList.Items.Count() = 0 Or ltbOrderByList.Items.Count() = 1 Then Exit Sub End If Dim liItem As ListItem Dim intItemIndex As Integer liItem = ltbOrderByList.SelectedItem intItemIndex = ltbOrderByList.SelectedIndex ltbOrderByList.Items.Insert(intItemIndex - 1, liItem) ltbOrderByList.Items.RemoveAt(intItemIndex) ltbOrderByList.ClearSelection() ltbOrderByList.SelectedIndex = intItemIndex - 1 End Sub
The last two lines are my attempt to manually set the selected item so multiple items definitly aren't selected. If there is an easier way of doing this I would also appreciate it if you could tell me too! :D Cheers Ian -
hi Looking for a bit of help. I have an asp.net listbox. I am wanting to manually be able to order the box by clicking a button. got everything set up but I keep getting an error saying that I can't have multiple selections on the list box when it is set as a single selection. I don't really know where I am going wrong so if anyone can help me I would most appreciate it. My code for the button click is as follows.
Protected Sub btOrderElementUp_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btOrderElementUp.Click If ltbOrderByList.Items.Count() = 0 Or ltbOrderByList.Items.Count() = 1 Then Exit Sub End If Dim liItem As ListItem Dim intItemIndex As Integer liItem = ltbOrderByList.SelectedItem intItemIndex = ltbOrderByList.SelectedIndex ltbOrderByList.Items.Insert(intItemIndex - 1, liItem) ltbOrderByList.Items.RemoveAt(intItemIndex) ltbOrderByList.ClearSelection() ltbOrderByList.SelectedIndex = intItemIndex - 1 End Sub
The last two lines are my attempt to manually set the selected item so multiple items definitly aren't selected. If there is an easier way of doing this I would also appreciate it if you could tell me too! :D Cheers Iantry this instead of
Senseicads wrote:
ltbOrderByList.ClearSelection() ltbOrderByList.SelectedIndex = intItemIndex - 1
ltbOrderByList.Items[ltbOrderByList.SelectedIndex].Selected = false; ltbOrderByList.SelectedIndex = intItemIndex - 1
Regards, Sylvester G sylvester_g_m@yahoo.com
-
try this instead of
Senseicads wrote:
ltbOrderByList.ClearSelection() ltbOrderByList.SelectedIndex = intItemIndex - 1
ltbOrderByList.Items[ltbOrderByList.SelectedIndex].Selected = false; ltbOrderByList.SelectedIndex = intItemIndex - 1
Regards, Sylvester G sylvester_g_m@yahoo.com
Thanks I was able to just set the selected to true after my clearselection. Thanks for the help.
ltbOrderByList.ClearSelection() ltbOrderByList.Items(intItemIndex - 1).Selected = True
So is it not possible to use selectedIndex like I was attempting to then? The intellisense says that SelectedIndex is used to "get or set" the index of the selected item? cheers Ian