Which events do I trap to change properties for the fpCombo

Posted by: j2associates on 8 September 2017, 12:46 pm EST

  • Posted 8 September 2017, 12:46 pm EST

    Hello all,


    I have a spread with a column set to ComboBoxCellType. I want to change some of the fpCombo properties (eg BackColor). What event do I trap to do this? Changes made in ComboDropDown do not have any effect and ComboBoxCellType does not appear to fire the SubEditorOpening event. Thanks in advance for any ideas and/or suggestions!

  • Replied 8 September 2017, 12:46 pm EST

    Hello,


    You can either create a cutom celltype like I layed out in my last post to you. Or you can catch the EditModeOn event and get the EditingControl from the Spread and cast it as a FpCombo object.

  • Replied 8 September 2017, 12:46 pm EST

    Hello Scott,


    Thanks for the timely response! Unless I am missing something, it appears that the editor properties have already been set by the time the EditModeOn event is fired because changes such as the below seem to have no effect.


    Private Sub FpSpread1_EditModeOn(ByVal sender As Object, ByVal e As System.EventArgs) Handles FpSpread1.EditModeOn
        With DirectCast(sender, FarPoint.Win.Spread.FpSpread)
            If TypeOf .EditingControl Is FpCombo Then
                DirectCast
    (.EditingControl, FpCombo).Parent.BackColor = Color.Aquamarine
            End If
        End With
    End Sub

     
  • Replied 8 September 2017, 12:46 pm EST

    Try removing the Parent class from your call...

    DirectCast(.EditingControl, FpCombo).BackColor = Color.Aquamarine
  • Replied 8 September 2017, 12:46 pm EST

    Hello Bob,


    That doesn't make any difference either. The code executes and properties are changed but the display does not change, it is still black on white. We are using the latest maintenance release if that makes a difference.

    Private Sub FpSpread1_EditModeOn(ByVal sender As Object, ByVal e As System.EventArgs) Handles FpSpread1.EditModeOn
    With DirectCast(sender, FarPoint.Win.Spread.FpSpread)
    If TypeOf .EditingControl Is FpCombo Then
    With DirectCast
    (.EditingControl, FpCombo)
    .BackColor = Color.Aquamarine
    .ForeColor = Color.Red
    End With
    End If
    End With
    End Sub
     
  • Replied 8 September 2017, 12:46 pm EST

    I am also using the latest maintenance release and it is working for me(see attachment).

    2007/08/editor.JPG
  • Replied 8 September 2017, 12:46 pm EST

    Hello Bob,


    Maybe I am not communicating clearly here. I am looking to change properties of the dropped FpCombo. I tried placing the code in both the EditModeOn and also ComboDropDown events. The attached screenshot is from the EditModeOn code posted above.


     


    2007/08/ComboBoxCellType_Dropped.JPG
  • Replied 8 September 2017, 12:46 pm EST

    I had an inkling that's what you were wanting.  There is no ListControl associated with the default combobox so you have to create one and assign the ListBox of the combo to it...

    Private Sub FpSpread1_EditModeOn(ByVal sender As Object, ByVal e As System.EventArgs) Handles FpSpread1.EditModeOn
    If TypeOf FpSpread1.EditingControl Is FarPoint.Win.FpCombo Then
          Dim c As FarPoint.Win.FpCombo = CType(FpSpread1.EditingControl,FarPoint.Win.FpCombo)
          Dim lb As New ListBox
          lb.BackColor = Color.LightBlue
          lb.ForeColor = Color.Red
          lb.Items.AddRange(c.List.ToArray())
          c.ListControl = lb
        End If

    End Sub
  • Replied 8 September 2017, 12:46 pm EST

    Thanks Bob, that's what I was looking for! Is there an easy way using MouseMove to determine which list item the user has moused over?
  • Replied 8 September 2017, 12:46 pm EST

    I am not familiar with a way to use the spreads MouseMove to determine which list item the user has moused over.  I also do not see anything in the properties of the ListControl that would allow you to get to this item.  There are only "selected" properties.
  • Replied 8 September 2017, 12:46 pm EST

    Hello Bob,


    Thanks for pointing the way! I dug around in the ListBox class and there is a convenient IndexFromPoint method that was exactly what I was looking for. So now my code is working quite nicely as below. I wanted to HighLight the mouse over item when the FpCombo was dropped which is what the extra code accomplishes.


    I changed to use the ComboDropDown and ComboCloseUp events instead of the EidtModeOn and EditModeOff events because they occurred more closely together.  Thanks again for getting me started!


    ' Remove the event handler added in ComboDropDown.
    Private Sub FpSpread1_ComboCloseUp(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.EditorNotifyEventArgs) Handles FpSpread1.ComboCloseUp
        If TypeOf DirectCast(sender, FarPoint.Win.Spread.FpSpread).EditingControl Is FpCombo Then
            With DirectCast
    (DirectCast(sender, FarPoint.Win.Spread.FpSpread).EditingControl, FpCombo).ListControl
                RemoveHandler .MouseMove, AddressOf ListBox_MouseMove
            End With
        End If
    End Sub
    'FpSpread1_ComboCloseUp

    Private Sub FpSpread1_ComboDropDown(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.EditorNotifyEventArgs) Handles FpSpread1.ComboDropDown
        With DirectCast(sender, FarPoint.Win.Spread.FpSpread)
            If TypeOf .EditingControl Is FpCombo Then
                Dim
    combo As FpCombo = DirectCast(.EditingControl, FpCombo)
                Dim listbox As New ListBox
                With listbox
                    .BeginUpdate()
                    .Items.AddRange(combo.List.ToArray())
                    .EndUpdate()
                    .BorderStyle = BorderStyle.None
                    .BackColor = Color.LightBlue
                    .ForeColor = Color.Red
                    ' Handle mouse move events in the list box to highlight the move over item.
                    AddHandler .MouseMove, AddressOf ListBox_MouseMove
                End With
                combo.ListControl = listbox
            End If
        End With
    End Sub
    'FpSpread1_ComboDropDown

    ' Highlight and select the mouse over item within the list box displayed when FpCombo drops.
    Private Sub ListBox_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        With DirectCast(sender, ListBox)
            If .SelectedIndex <> .IndexFromPoint(e.X, e.Y) Then
                .SetSelected(.IndexFromPoint(e.X, e.Y), True)
            End If
        End With
    End Sub
    'ListBox_MouseMove

     
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels