Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to get hidden textbox from combobox

Status
Not open for further replies.

SBendBuckeye

Programmer
May 22, 2002
2,166
US
Hello all,

I am trying to get a reference to the hiddent textbox behind a combobox using the following code. The handle changes but FromHandle(handle) line always returns Nothing.
Code:
<DllImport("user32", CharSet:=CharSet.Auto)> _
Private Shared Function FindWindowEx(ByVal hwndParent As IntPtr, _
                                     ByVal hwndChildAfter As IntPtr, _
                                     <MarshalAs(UnmanagedType.LPTStr)> _
                                     ByVal lpszClass As String, _
                                     <MarshalAs(UnmanagedType.LPTStr)> _
                                     ByVal lpszWindow As String) As IntPtr
  ' Function body should be empty.
End Function 'FindWindowEx

' Control is a ComboBox.
Public Shared Function GetHiddenTextBox(ByVal control As Windows.Forms.Control) As Control
  Dim handle As IntPtr = control.Handle
  If GetType(System.Windows.Forms.ComboBox).IsAssignableFrom(control.GetType) Then
    handle = FindWindowEx(handle, IntPtr.Zero, "EDIT", "" & Microsoft.VisualBasic.Chr(0) & "")
  End If
  Return System.Windows.Forms.Control.FromHandle(handle)
End Function 'GetHiddenTextBox
Does anyone have any ideas and/or suggestions? Thanks in advance!

Have a great day!

j2associatesNO_SPAM@gmail.com
 
What are you actually trying to do? There may be a simpler solution than refering to this hidden control directly.
 
Apparently this works in 2005 but not in 2003. When a user clears a combobox by selecting everything in the textbox and then deleting it, the combobox selected index is set to zero but the SelectedIndexChanged event is not fired. I was hoping to get the textbox and then set a handler to its changed event. Thanks for the response...

Have a great day!

j2associatesNO_SPAM@gmail.com
 
You can probably get what you need using the ComboBox.KeyUp event or similar.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top