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:
cboGeneric.enabled = false
cboGeneric.foreColor= color.black
and this fails.. i have also trid severla other tricks and they have failed also.. any sugestions are appreciated...
Re: how to: Combobox uneditable yet Text remain Black??
Set the DropDownStyle property to DropDownList.
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....
Re: how to: Combobox uneditable yet Text remain Black??
Quote:
yet the text remains black even after implicitly telling it to use black as the foreColor
what where you expecting?
Re: how to: Combobox uneditable yet Text remain Black??
Quote:
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...
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.
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.
Quote:
There is no property to make the textbox readonly
Textboxes do have a ReadOnly property...
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!
Re: how to: Combobox uneditable yet Text remain Black??
:D 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.)
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.
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. :rolleyes:
ComboBox Readonly
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.
Re: how to: Combobox uneditable yet Text remain Black??
Quote:
Lol Stimbo..i meant still Grey!...not black..sorry about that..
Kleinma, did you get confused too? :D
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?
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...
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)
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.
1 Attachment(s)
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.
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!
Re: how to: Combobox uneditable yet Text remain Black??