Link to home
Start Free TrialLog in
Avatar of Ark
ArkFlag for Russian Federation

asked on

ComboBoxes highlited after resizing?

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
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ark

ASKER

Thanks, Idle
Small addition:

    Private Const WM_SIZE As Integer = &H5& 'To handle Maximizing/restoring
'..................
  Case WM_ENTERSIZEMOVE, WM_SIZE
'.................
Avatar of Ark

ASKER

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
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".  =\