Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

ComboBoxes highlited after resizing?

Posted on 2007-08-04
4
Medium Priority
?
333 Views
Last Modified: 2010-08-05
After resizing winform with a nuber of databound comboboxes (Style=DropDown, Autocomplete=SuggestAppend) with an anchor set to left,top,right all them resized properly but all get highlighted. Is this a bug or future? Currently I use:

    Private Sub frmMain_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        UnHighlightCombos(Me)
    End Sub

    Private Sub UnHighlightCombos(ByVal ctrlParent As Control)
        For Each ctrl As Control In ctrlParent.Controls()
            If TypeOf ctrl Is ComboBox Then
                If Not ctrl.Focused Then
                    CType(ctrl, ComboBox).SelectionLength = 0
                End If
            Else
                If ctrl.Controls.Count > 0 Then
                    UnHighlightCombos(ctrl)
                End If
            End If
        Next
    End Sub

but this way you can see blinking selection over combo's. Is there a better way to bypass this 'future'?

Thanks
Ark
0
Comment
Question by:Ark
  • 2
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1000 total points
ID: 19634623
Hi Ark,

Try something like this out...

Public Class Form1

    Private combos As New ArrayList
    Private Const WM_ENTERSIZEMOVE As Integer = &H231&
    Private Const WM_EXITSIZEMOVE As Integer = &H232

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        GetCombos(Me)
    End Sub

    Private Sub GetCombos(ByVal ctrlParent As Control)
        For Each ctrl As Control In ctrlParent.Controls()
            If TypeOf ctrl Is ComboBox Then
                combos.Add(New MyComboBox(ctrl))
            Else
                If ctrl.Controls.Count > 0 Then
                    GetCombos(ctrl)
                End If
            End If
        Next
    End Sub

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        Select Case m.Msg
            Case WM_ENTERSIZEMOVE
                MyComboBox.SuppressSetText = True

            Case WM_EXITSIZEMOVE
                MyComboBox.SuppressSetText = False

        End Select

        MyBase.WndProc(m)
    End Sub

    Private Class MyComboBox
        Inherits NativeWindow

        Private Const WM_GETTEXTLENGTH As Integer = &HE
        Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As IntPtr, ByVal hWnd2 As IntPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As IntPtr

        Public Shared SuppressSetText As Boolean = False

        Public Sub New(ByVal cb As ComboBox)
            Dim editWnd As IntPtr = FindWindowEx(cb.Handle, IntPtr.Zero, "Edit", vbNullString)
            If Not editWnd.Equals(IntPtr.Zero) Then
                Me.AssignHandle(editWnd)
            End If
        End Sub

        Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
            If MyComboBox.SuppressSetText Then
                Select Case m.Msg
                    Case WM_GETTEXTLENGTH
                        Return ' Suprress the message

                End Select
            End If
            MyBase.WndProc(m)
        End Sub

    End Class

End Class
0
 
LVL 28

Author Comment

by:Ark
ID: 19635490
Thanks, Idle
Small addition:

    Private Const WM_SIZE As Integer = &H5& 'To handle Maximizing/restoring
'..................
  Case WM_ENTERSIZEMOVE, WM_SIZE
'.................
0
 
LVL 28

Author Comment

by:Ark
ID: 19635615
PS
I'm woundering how long programmers will 'dance like monkey' around MS bugs? Here are some handlers from my app:
#Region " Event handlers"
    'Handles MS bug (KB327244) - ComboBox Does Not Clear When You Set SelectedIndex to -1
    Private Sub HadleComboMS_Bug(ByVal sender As Object, ByVal e As System.EventArgs)
        If bFromCode Then Exit Sub
        Dim cbo As ComboBox = CType(sender, ComboBox)
        If cbo.SelectedIndex = -1 Then
            bFromCode = True
            cbo.SelectedIndex = 0
            cbo.SelectedIndex = -1
            bFromCode = False
        End If
    End Sub
   
 'Handles MS bug (KB313513) - PRB: InvalidCastException When You Bind DateTimePicker That Contains a Null Value
    Private Sub DTFormatter(ByVal sender As Object, ByVal e As ConvertEventArgs)
        If Not e.DesiredType Is GetType(DateTime) Then Return
        If e.Value.GetType Is GetType(System.DBNull) Then e.Value = CType("1/1/1800", System.DateTime)
    End Sub
   
 'Handles MS bug (KB313513) - PRB: InvalidCastException When You Bind DateTimePicker That Contains a Null Value
    Private Sub DTParser(ByVal sender As Object, ByVal e As ConvertEventArgs)
        If Not e.DesiredType Is GetType(DateTime) Then Return
        If Not e.Value.GetType Is GetType(DateTime) Then Return
        Dim value As String = CType(e.Value, String)
        If value.Equals("1/1/1800") Then e.Value = System.DBNull.Value
    End Sub
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 19635881
You're welcome!  Glad to solve a problem that actually required a little thought and tinkering...  ;)

But I wholeheartedly agree...it is unfortunate that coders have to spend extra time writing "hacks" to fix things that should work correctly "out of the box".  =\
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question