开发者

Moving A Listitem To The Top of A Listbox

When the user selects a name in the listbox and clicks a button I save the name in a var called "parent".

What I want to do is programmatically move the selected name to the top of the list and take that whole list and drop it in a dropdown. I started the code below but don't know how to move the selected list item (开发者_JS百科parent) to the top of the list??

Private Sub GoLower(ByVal parent As String, 
        ByVal lst As ListBox, 
        ByVal ddl As DropDownList) 

        ddl.Items.Clear() 

        For Each item As ListItem In lst.Items 
            ddl.Items.Add(item.Text) 
            'MOVE the item that is parent to top of ddl???? 
        Next 

End Sub


Construct the list box in any order, then move the one you want to the top. This is in C#, but the VB.net equivalent should be obvious:

 ListItem item = list.SelectedItem;
 // or find the required item another way, such as .FindByValue
 list.Items.Remove(item);
 list.Items.InsertAt(0, item);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜