-
July 11th, 2008, 09:03 AM
#1
Set Combobox index text
I'm trying to set a certain index in a combobox to be a value returned by a Database Query. So far, SelectedItem displays the text, but setting it equal to the string only selects the index at which that string is present, but doesn't change the string in the current index selected. How can i change the text in an index of a combobox?
-
July 11th, 2008, 05:06 PM
#2
Re: Set Combobox index text
I dont think that anyone is acctually getting what the problem here is..
Post some code to demonstrate please...
Thanks..
Gremmy..
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
July 11th, 2008, 07:06 PM
#3
Re: Set Combobox index text
Originally Posted by GremlinSA
I dont think that anyone is acctually getting what the problem here is..
Post some code to demonstrate please...
Thanks..
Gremmy..
Yeah, I can do that.
Code:
ComboBox1.SelectedIndex = 0
ComboBox1.SelectedItem = tasks("Tech")
What happens is that SelectedItem = tasks("Tech") moves the selected index to that of the tech that matches the text of Tasks("Tech"). For example, if it was A and the combobox had Blank,A,B,C in it, it would just move it down to A, but leave Blank as it is. What I want to do is make Index 0, blank, equal the same text that tasks("tech") return. I want to do this, because I want to be able to make Blank the first Tech and fill in the rest. It's easy to add indexs, but not change the text of one already present.
Microsoft Visual Basic 2008 Express Edition
.NET Framwork 3.5 Beta SP1
-
July 11th, 2008, 08:38 PM
#4
Re: Set Combobox index text
Just Add the item at the position you want, ie 0
-
July 12th, 2008, 01:51 AM
#5
Re: Set Combobox index text
If you want to update the currently selected item in the combo-box, then things are slightly trickier. From a quick test, setting the .SelectedItem = "New Value" doesn't update the combo-box. However, setting .Items(.SelectedIndex) = "New Value" does work.
I hope that helps solve you problem.
If any of the gurus out can tell me why one method works and the other doesn't, I'd be most grateful...
Help from me is always guaranteed!*
VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.
*Guarantee may not be honoured.
-
July 12th, 2008, 05:58 AM
#6
Re: Set Combobox index text
This is one of those, well that's how it is, things that is difficult to explain..
At best i assume that .SeletedItem object is a clone of the .Item(x), and any changes made to a clone does not replicate back to the original object..
I'll look into this a little deeper and report back later..
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|