Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

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)

Posted

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.

Posted

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!

Visit: VBSourceSeek - The VB.NET sourcecode library

 

 

"A mere friend will agree with you, but a real friend will argue."
Posted
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?
Posted (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 by APaule
  • Moderators
Posted

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

Visit...Bassic Software
Posted
.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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...