Results 1 to 20 of 20

Thread: how to: Combobox uneditable yet Text remain Black??

  1. #1

    Thread Starter
    Lively Member smilbuta's Avatar
    Join Date
    Apr 2005
    Location
    Orlando
    Posts
    104

    how to: Combobox uneditable yet Text remain Black??

    Hello community...

    I wish to make a combo box uneditable untill an event. The combo box is bound to a datasource so data is visible within the box at its creation. I want this data do be black instead of the greyed out default in an uneditable combo box.

    I have tried the following

    VB Code:
    1. cboGeneric.enabled = false
    2. cboGeneric.foreColor= color.black

    and this fails.. i have also trid severla other tricks and they have failed also.. any sugestions are appreciated...

  2. #2
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: how to: Combobox uneditable yet Text remain Black??

    Set the DropDownStyle property to DropDownList.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  3. #3

    Thread Starter
    Lively Member smilbuta's Avatar
    Join Date
    Apr 2005
    Location
    Orlando
    Posts
    104

    Re: how to: Combobox uneditable yet Text remain Black??

    Ok, a changed the drop down style, yet the text remains black even after implicitly telling it to use black as the foreColor.

    Mayhaps im not understanding the difference between dropdown and dropdownlist....

  4. #4
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: how to: Combobox uneditable yet Text remain Black??

    yet the text remains black even after implicitly telling it to use black as the foreColor
    what where you expecting?
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  5. #5
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: how to: Combobox uneditable yet Text remain Black??

    Combobox uneditable yet Text remain Black
    In VB6 we set the combobox's .locked property to true.

    See if you have a .locked property in vb.net

    Hope this helps...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  6. #6
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: how to: Combobox uneditable yet Text remain Black??

    There is no property to make the combobox readonly.

    The Locked property in VB.NET makes the control unmovable during designtime.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  7. #7
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: how to: Combobox uneditable yet Text remain Black??

    Locked is only for locking a control during design time.

    Can I clarify something - do you want to make the entire combobox black?? which would signal that it can't be edited....

    You would do as suggested and set its DropDownStyle to List and change its BackColor to black.

    Apologies if I have misunderstood.

    There is no property to make the textbox readonly
    Textboxes do have a ReadOnly property...
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  8. #8

    Thread Starter
    Lively Member smilbuta's Avatar
    Join Date
    Apr 2005
    Location
    Orlando
    Posts
    104

    Re: how to: Combobox uneditable yet Text remain Black??

    Lol Stimbo..i meant still Grey!...not black..sorry about that..

    As for the rest , thank you.. i figure ill just overlay the control witha text box and hide the one i dont need upon an event... and just make the text box read only...

    Thanx guys!

  9. #9
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: how to: Combobox uneditable yet Text remain Black??

    Now it all makes sense.

    Umm, never done this before but there are loads of examples where you create your own control (combobox in this case) for example that inherits fromt the VB combobox but that is also read only (you add extra properties). That may work but someone more experienced should post to confirm that it's not a massive task and simple to achieve....

    (people have posted examples with a textbox only accepting numeric input for example.)
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  10. #10
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: how to: Combobox uneditable yet Text remain Black??

    If your gonna overlay with a textbox then might as well simulate the combo with a textbox and a listbox.

  11. #11
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: how to: Combobox uneditable yet Text remain Black??

    Here's a solution written in C#. Perhaps someone would be kind enough to alter it to VB.NET for you...? I would....if I could.

    ComboBox Readonly
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  12. #12
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: how to: Combobox uneditable yet Text remain Black??

    when setting a control's enabled property to false, the default behavior is to gray out the control (as you know)

    This is a standard thing in windows, and if you were to change it to make it black instead of gray, then it would just confuse the end users, and they would likely think something is wrong with the program.

    If you came across a control that looked like it was enabled, but it wasn't, wouldn't that confuse you? Unless you have some specific reason, I would leave it as it is, and let it look disabled, because it is disabled.

  13. #13
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: how to: Combobox uneditable yet Text remain Black??

    Lol Stimbo..i meant still Grey!...not black..sorry about that..
    Kleinma, did you get confused too?
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  14. #14
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: how to: Combobox uneditable yet Text remain Black??

    well then I don't get it because a combobox is grayed out when its not enabled.

    So what is the issue then?

  15. #15

    Thread Starter
    Lively Member smilbuta's Avatar
    Join Date
    Apr 2005
    Location
    Orlando
    Posts
    104

    Re: how to: Combobox uneditable yet Text remain Black??

    The reason for the odd request is as follows...

    Users view a combo box with information they are unable to change at time of viewing. Upon a certain update request event... the combo box would swich from enabled=false to enabled=true.

    The issue arose because the text was faint in the unenabled box, some users could not read it clearly to confirm the contents, thus my intention was to simply make the text more visible to the users.

    I fully understand the reason for leaving greyed out as explained and will just have to programaticaly create a work around for those users who insists otherwise.


    THank you all.. for your help.. i learn something new every time i come here...

  16. #16
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: how to: Combobox uneditable yet Text remain Black??

    Another possible solution could be achived using 2 comboboxes. One is "DropDownList" and another is normal "DropDown".
    Load the data in both comboboxes.
    Place them in same location on the form.
    In 'ReadOnly' mode show the "DropDownList".
    In 'EditMode' show the "DropDown" box.

    (I don't know if there is a way to change the style during runtme in VB.NET)
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  17. #17
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: how to: Combobox uneditable yet Text remain Black??

    What you can do is to overlay a readonly textbox on top of the combobox and play with the visible property of both controls to get what you want.

  18. #18
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: how to: Combobox uneditable yet Text remain Black??

    I got a bit interested, so I made a custom class that inherits from Combobox, but has an option to simply disallow the user to change the selection. It won't look disabled, it just won't allow them to drop down the combo, or use the keyboard to change the selection until you change the AllowToDropDown property to true (which can be done at design time or runtime)

    this should give you what you want, and maybe teach you a thing or 2 about extending the standard controls to fit your needs, without workarounds like adding extra controls and doing visible swaps with them.

    The code is commented so you can see whats going on.

    Since I don't upload the compiled files, when you open the project, you need to build the project first, then you can view form1.
    Attached Files Attached Files

  19. #19

    Thread Starter
    Lively Member smilbuta's Avatar
    Join Date
    Apr 2005
    Location
    Orlando
    Posts
    104

    Re: how to: Combobox uneditable yet Text remain Black??

    Oh wow...ill have a look.. My Kung-Fu is still not strong enough to understand how to make my own clases yet..but ..this will get me started im sure!

    Thanx!

  20. #20
    Member
    Join Date
    Mar 2005
    Posts
    47

    Re: how to: Combobox uneditable yet Text remain Black??

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width