ComboBoxCellType update bound list when user selects an item

Posted by: kbj on 9 January 2022, 7:15 am EST

  • Posted 9 January 2022, 7:15 am EST

    The ComboBoxCellType updates a bound record after the user leaves the cell. Is there a way to force an update after the use selects a different item from the drop down list?
    Here's a quick and dirty example that I'd like to see the value in the second column change when the user selects an item in the first column.

    Imports System.ComponentModel
    Imports FarPoint.Win
    Imports FarPoint.Win.Spread
    Imports FarPoint.Win.Spread.CellType
    Public Class Form1
    Public months As BindingList(Of classMonth)
    Private WithEvents ct As ComboBoxCellType
    Private WithEvents wb As FpSpread
    Private WithEvents ws As SheetView
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
    wb = New FpSpread
    ws = New SheetView
    wb.Dock = DockStyle.Fill
    ct = comboFromEnum(GetType(enumMonths))
    ws.DataSource = months
    ws.ColumnCount = 2
    ws.Columns(0).DataField = "itemData"
    ws.DataAutoHeadings = False
    ws.DataAutoCellTypes = False
    ws.Columns(0).CellType = ct
    End Sub
    Private Sub loadList()
    months = New BindingList(Of classMonth)
    months.Add(New classMonth(enumMonths.April))
    months.Add(New classMonth(enumMonths.October))
    months.Add(New classMonth(enumMonths.January))
    End Sub

    Public Function comboFromEnum(t As Type) As ComboBoxCellType
    Dim result = New ComboBoxCellType
    result.ItemData = Array.ConvertAll(Of Integer, String)(System.Enum.GetValues(t), Function(x) x.ToString())
    result.Items = System.Enum.GetNames(t)
    result.EditorValue = EditorValue.ItemData
    result.DropDownOptions = DropDownOptions.Button
    result.Editable = False
    Return result
    End Function
    End Class
    Public Class classMonth
    Public Property number As enumMonths
    Public Property itemData As String
    Return Int(number).ToString
    End Get
    Set(value As String)
    [Enum].TryParse(value, number)
    End Set
    End Property
    Public Sub New(number As enumMonths)
    Me.number = number
    End Sub
    End Class
    Public Enum enumMonths
    End Enum
  • Replied 12 January 2022, 7:53 pm EST


    You can handle the EditChange event and then check if the EditingControl is FpCombo then switch the EditMode on and then off, this will force the value of the cell to update as you change the item of the combo box. If you want this behavior for only specific column then you can also check if the EditChange was fired for that column and then do the processing as described above.

    Public Sub EditChange(sender As Object, e As EditorNotifyEventArgs) Handles wb.EditChange
    If (e.EditingControl.GetType().Name = "FpCombo") Then
    e.View.EditMode = False
    e.View.EditMode = True
    End If
    End Sub

    If you have any issues, please let us know.

Need extra support?

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

Learn More

Forum Channels