Does anyone know a way to make a combobox "read-only", similar to the read-only property of a textbox?
In essence, make a combobox readonly...making the combobox text not gray out but be disabled. There is no readonly property for a combobox like there is for a text box.
Thx,
Jason
-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)
<Id>Tuk80NG07k68AkJ75+fGAw==</Id>
try set the dropdown style to "dropdownlist"
Hope it helps
Regards,
Norton
"Jason Simard via .NET 247" <anon...@dotnet247.com> ???
news:u2%23EL67U...@TK2MSFTNGP11.phx.gbl ???...
Quick and dirty:
\\\
Private Declare Auto Function GetWindow Lib "user32.dll" ( _
ByVal hwnd As IntPtr, _
ByVal wCmd As Int32 _
) As IntPtr
Private Declare Auto Function SendMessage Lib "user32.dll" ( _
ByVal hwnd As IntPtr, _
ByVal wMsg As Int32, _
ByVal wParam As Boolean, _
ByVal lParam As Int32 _
) As Int32
Private Const EM_SETREADONLY As Int32 = &HCF
Private Const GW_CHILD As Int32 = 5
Private Function SetComboBoxReadOnly(ByVal ComboBox As ComboBox, ByVal Value As Boolean)
SendMessage( _
GetWindow( _
ComboBox.Handle, _
GW_CHILD _
), _
EM_SETREADONLY, _
Value, _
0 _
)
ComboBox.Refresh()
End Function
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
SetComboBoxReadOnly(Me.ComboBox1, Me.CheckBox1.Checked)
End Sub
///
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
/claes
"Herfried K. Wagner [MVP]" <hirf-spa...@gmx.at> wrote in message
news:2jbgrfF...@uni-berlin.de...
I don't think that this is a good idea. Yesterday I tried to implement
a readonly combobox. I didn't want to prevent the user from taking a
look at the dropdown part of the control. That worked fine by drawing
the items in an ownerdrawn mode that doesn't show the selection if the
control is readonly. Nevertheless, I was not able to prevent the user
from selecting an item. I subclassed the combobox's dropdown part and
played around with it (eating some messages etc.), and I tried to
disable the dropdown part, but this prevented the dropdown from closing
properly and/or the dropdown listbox's scrollbar to be disabled.
:-(
Well, if you still want to be able to see the drop-down list (but not select
anything) I guess it gets a bit trickier :-). The OP should have enough
to get him started though
/claes
The answer is already given in the first answer in this thread, however when
you do not catch an raised event, there is no problem at all, what are you
searching for ?
I think that the OP only wants to make the text(box) part of the combobox
readonly and that answer is given by norton.
:-)
Cor
Well, do you have an idea how to accomplish that?
;-)
> The OP should have enough to get him started though
ACK.
Mhm... Not sure what you are referring to. I wanted the user to be
able to dropdown the list but prevent him from selecting another item.
It's very simple to remove the item selection rectangle in the listbox
part of the combobox, but it's not as simple to make this part selection
insensitive.
No, sorry
/claes