Set Combobox index text
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Set Combobox index text

  1. #1
    Join Date
    Jun 2007
    Location
    .NET 3.5 Beta SP1, Visual Basic 2008 Express
    Posts
    225

    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?

  2. #2
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,770

    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.

  3. #3
    Join Date
    Jun 2007
    Location
    .NET 3.5 Beta SP1, Visual Basic 2008 Express
    Posts
    225

    Re: Set Combobox index text

    Quote 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

  4. #4
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,874

    Re: Set Combobox index text

    Just Add the item at the position you want, ie 0
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Aug 2005
    Location
    Imperial College London, England
    Posts
    490

    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.

  6. #6
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,770

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center