ReadOnly ComboBox

A

Ahmed

Hello everyone,

I am trying to create a "ReadOnly" Combobox. I know I can disable the
combobox but it will be unreadable for our users. So, I decided to
extend the built in combobox and I succeeded in building what I want.
The only problem is when the combobox is read only the mouse up event
does not get fired.

Here is mycode.

Protected Overrides Sub WndProc(ByRef m As Message)

If m_ReadOnly = True Then
'ignore the WM_LBUTTONDOWN and WM_LBUTTONDBLCLK
If m.Msg = &H201 Or m.Msg = &H203 Then
Return
'This is for debugging purposes: the WM_LBUTTONUP is
'Captured
ElseIf m.Msg = &H202 Then
Dim i As Integer = 1
End If

End If
'Call base method so delegates receive event
MyBase.WndProc(m)
End Sub

if the LBUTTONUP is captured why the mouseup event is not fired?

Thanks

Ahmed
 
C

Crouchie1998

First of all, you should be checking for the WM messages in WndProc.
Secondly, how can you return from a sub?

It would be something like this:

If m.Msg = WM_LBUTTONDBLCLK Then
MyBase.WndProc(m)
End If

The above will ignore the left mouse button double click providing you
declare the constant, WM_LBUTTONDBLCLK. Do the same for left mouse down
which is what you wanted.

Get into the habit of using the constants like in my example above:

Private Const WM_LBUTTONDBLCLK = &H203
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202

That way, its so much easier to read & less mistakes will be made.

With the left button mouse up, why have you declared 'i' as an integer when
nothing is done with it & its also a local variable?

Crouchie1998
BA (HONS) MCP MCSE
 
A

Ahmed

Exactly,

The dropdown basically should not drop down if readonly =true.

Protected Overrides Sub WndProc(ByRef m As Message)
'Prevent list displaying if ReadOnly
If m_ReadOnly = True Then
If m.Msg = WM_LBUTTONDOWN Or m.Msg = WM_LBUTTONDBLCLK Then
Return
End If
MyBase.WndProc(m)
End Sub

Crouchie1998, I had Dim i as integer =1 for debugging purposes. I had
break point there to check if the WM_LBUTTONUP is captured and it does.
but the mouseup event is still not fired.
 
H

Herfried K. Wagner [MVP]

Ahmed said:
The dropdown basically should not drop down if readonly =true.

I don't have a solution for you, but notice that the dropdown can be shown
by pressing certain keys too, F4, for example.
 
A

Ahmed

Thanks for the reply,

Here is the code cleaned up

Protected Overrides Sub WndProc(ByRef m As Message)
'Prevent list displaying if ReadOnly
If m_ReadOnly = True Then
If m.Msg = WM_LBUTTONDOWN Or m.Msg = WM_LBUTTONDBLCLK Then
Return
End If

End If

MyBase.WndProc(m)
End Sub

I had a break point at "dim i as integer =1" to check if the
WM_LBUTTONUP is captured or not. I used "return" to exit from the sub.
I believe it is the same as using "Exit Sub" . basically, what I did is
ignoring the left click and the left double click. However, I would
like to get the mouse up even to get fired.
 
A

Ahmed

Hi Herfried,

I already ignored the keyboard events in PreProcessMessage(ByRef msg As
Message) function. Here is the code. So the drop down does not get
focus.

Thanks.
 
A

Ahmed

Sorry Forgot the code:

Public Overrides Function PreProcessMessage(ByRef msg As Message) As
Boolean
'Prevent keyboard entry if control is ReadOnly
If m_ReadOnly = True Then
'Check if its a keydown message
If msg.Msg = WM_LBUTTONUP Then
Dim i As Integer = 1
End If
If msg.Msg = &H100 Then
'Get the key that was pressed
Dim key As Int32 = msg.WParam.ToInt32
'Ignore navigation keys
If key = Keys.Tab Or key = Keys.Left Or key =
Keys.Right Then
'Do nothing
Else
Return True
End If
End If
End If
'Call base method so delegates receive event
Return MyBase.PreProcessMessage(msg)
End Function
 
A

Ahmed

Is it possible to raise the mouse up event from the WndProc??

Please let me know.

Thanks

Ahmed
 
L

Larry Lard

Ahmed said:
Hello everyone,

I am trying to create a "ReadOnly" Combobox.

Perhaps you could describe what such a thing looks and behaves like? Do
you want users to be able to drop down the list, but then not be able
to change the selected item? Or not be able to drop down the list at
all?
 
A

Ahmed

What I am trying to do is the following:

User can not drop the list down if the combo box is readonly (ie they
are viewing a record). But, when the click on the combobox, a popup
message comes up asking them if they wants to update the record. If
yes, then the combobox functions normally.
 
A

Ahmed

For two reasons,

1) After disabling the combo box it won't fire any event.
2) People can not read what's in it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top