DropDownClosing and Filter Exception

2 posts, 0 answers
  1. Jay
    Jay avatar
    9 posts
    Member since:
    Feb 2011

    Posted 21 Jan Link to this post

    I updated to 2016 Q1 from 2014.  In 2014, I had worked around the problem of the drop down closing whenever the user tried to click on a filter row by subscribing to the drop down closing event.  Here was the code for that event which worked great for me:

                If TypeOf sender Is RadMultiColumnComboBox Then
                    rmc = sender
                    If rmc.SelectedIndex > -1 Then
                        '--- if focus is on a row, then let popup close
                        'Console.WriteLine("clicked on: " & CStr(rmc.SelectedIndex))
                    Else
                        '--- else, check mouse position and don't allow close if within popup window area
                        pt = rmc.EditorControl.TableElement.PointFromControl(MousePosition)
                        popTop = rmc.MultiColumnComboBoxElement.MultiColumnPopupForm.Top
                        popLft = rmc.MultiColumnComboBoxElement.MultiColumnPopupForm.Left
                        popHt = rmc.MultiColumnComboBoxElement.MultiColumnPopupForm.Height
                        popWd = rmc.MultiColumnComboBoxElement.MultiColumnPopupForm.Width
                        If pt.X >= popLft And pt.X <= popLft + popWd Then
                            If pt.Y >= popTop And pt.Y <= popTop + popHt Then
                                '--- should be click within window so leave it open
                                args.Cancel = True
                                rmc.Focus()
                            End If
                        End If
                    End If

                End If 

    Now, when a user clicks on the filter row, it opens the drop down so they can type in a filter but as before, they have to click on it twice to set the focus (a separate bug?). When they make the second mouse click with 2016Q1, I am now getting a null reference exception in Telerik.Wincontrols.UI.  I cannot even trap this error in a Try..Catch, it simply crashes the program.  Screenshot shows situation...user clicks drop down on Cust# field...clicks on filter row in customerName column, has to click again to set the focus and the POOF!

    Thanks in advance for help.

     

     


     
  2. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 25 Jan Link to this post

    Hello Jay,

    Thank you for writing.

    By design, RadMultiColumnComboBox is not supposed to allow filtering by using the grid filter row. The filtering behavior is available in the editable part of RadMultiColumnComboBox. Additional information is available here: http://docs.telerik.com/devtools/winforms/multicolumncombobox/filtering

    However, in order to prevent closing the drop down when typing the filter row, you should focus the active editor in the filter cell. Here is a sample code snippet which result is illustrated on the attached gif file:
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.CustomersTableAdapter.Fill(Me.NwindDataSet.Customers)
        Me.RadMultiColumnComboBox1.DataSource = Me.CustomersBindingSource
        Me.RadMultiColumnComboBox1.DisplayMember = "ContactName"
        Me.RadMultiColumnComboBox1.ValueMember = "CustomerID"
        Me.RadMultiColumnComboBox1.AutoSizeDropDownToBestFit = True
        Me.RadMultiColumnComboBox1.EditorControl.EnableFiltering = True
        Me.RadMultiColumnComboBox1.EditorControl.ShowFilteringRow = True
        AddHandler Me.RadMultiColumnComboBox1.DropDownClosing, AddressOf DropDownClosing
    End Sub
     
    Private Sub DropDownClosing(sender As Object, args As Telerik.WinControls.UI.RadPopupClosingEventArgs)
        If TypeOf sender Is RadMultiColumnComboBox Then
            Dim rmc As RadMultiColumnComboBox = sender
            If rmc.SelectedIndex > -1 Then
                '--- if focus is on a row, then let popup close
                'Console.WriteLine("clicked on: " & CStr(rmc.SelectedIndex))
            Else
                '--- else, check mouse position and don't allow close if within popup window area
                Dim pt As Point = rmc.EditorControl.TableElement.PointFromControl(MousePosition)
                Dim popTop As Integer = rmc.MultiColumnComboBoxElement.MultiColumnPopupForm.Top
                Dim popLft As Integer = rmc.MultiColumnComboBoxElement.MultiColumnPopupForm.Left
                Dim popHt As Integer = rmc.MultiColumnComboBoxElement.MultiColumnPopupForm.Height
                Dim popWd As Integer = rmc.MultiColumnComboBoxElement.MultiColumnPopupForm.Width
                If pt.X >= popLft And pt.X <= popLft + popWd Then
                    If pt.Y >= popTop And pt.Y <= popTop + popHt Then
                        '--- should be click within window so leave it open
                        args.Cancel = True
                        If rmc.EditorControl.ActiveEditor IsNot Nothing Then
                            Dim editor As RadTextBoxEditor = TryCast(rmc.EditorControl.ActiveEditor, RadTextBoxEditor)
                            If editor IsNot Nothing Then
                                Dim editorElement As RadTextBoxEditorElement = TryCast(editor.EditorElement, RadTextBoxEditorElement)
                                editorElement.Focus()
                            End If
     
                        End If
                    End If
                End If
            End If
        End If
    End Sub

    Note that the grid may use different editor types. Feel free to modify the above code in a way to suit your requirement best. 

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top