mike55 Posted May 20, 2005 Posted May 20, 2005 Hi, Am selecting a list of groups from my database into a dataset, this dataset is then binded to a dropdown list. What I need to do is to add to the top of the dropdown list a value "Master", any suggestions. I have no problem adding the value to the bottom of the dropdown list. Can anyone make a suggestion. Mike55 Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
APaule Posted May 20, 2005 Posted May 20, 2005 If it has to be a bound control, you should handle this in the select statement of the dataadapter that fills the dataset. I suggest you use a "union select" and put your "Master"-entry in the first select. Quote
stustarz Posted May 20, 2005 Posted May 20, 2005 Once you have bound the dropdown to the dataset try using this : Dim objSelectItem As New ListItem("Item To Add Text", -1) objSelectItem.Selected = True Me.DropDownLost.Items.Insert(0, objSelectItem) This should add a new item at the top of the dropdown list - which has been automatically set to be selected. This has worked for me using a datareader to populate the list but i havent tested with a dataset - hence the reason i say it 'should' work :) Good Luck! Quote Visit: VBSourceSeek - The VB.NET sourcecode library "A mere friend will agree with you, but a real friend will argue."
APaule Posted May 21, 2005 Posted May 21, 2005 stustarz, I bet this one won't work with a bound control! :D Quote
Moderators Robby Posted May 21, 2005 Moderators Posted May 21, 2005 If you do the Insert after DaytaBind it does work. Quote Visit...Bassic Software
APaule Posted May 22, 2005 Posted May 22, 2005 If you do the Insert after DaytaBind it does work.But what about the DisplayMember and the ValueMember? How has the object to be formed that you add? Quote
Moderators Robby Posted May 23, 2005 Moderators Posted May 23, 2005 The insert method has an index and item parm, so they are handled as other items are within the bound control.... dd1.Items.Insert(int_index, string_item) Quote Visit...Bassic Software
APaule Posted May 23, 2005 Posted May 23, 2005 (edited) Sorry folks, back to the start (or better choose my solution). :cool: What do you think, does the following exception want to tell us?Cannot modify the Items collection when the DataSource property is set.I told you, but nobody seemed to believe me. :p ;) Edited May 23, 2005 by APaule Quote
Moderators Robby Posted May 23, 2005 Moderators Posted May 23, 2005 I'm not sure how your doing it but it has always worked for me, here's a sample .... With dd .DataSource = dv .DataMember = "SomeTable" .DataValueField = "Some_id" .DataTextField = "Some_name" .DataBind() .Items.Insert(0, "Some text") End With Quote Visit...Bassic Software
APaule Posted May 23, 2005 Posted May 23, 2005 .DataBind()Oops, sorry! When I saw .DataBind(), I realized that the question is about Web components. I was talking about Windows components, because there you definitely can't change the collection of a bound control. Sorry again, my fault. :-\ :o :o Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.