Databinding and Checkbox caption

Posted by: sameek on 8 September 2017, 12:29 pm EST

  • Posted 8 September 2017, 12:29 pm EST

    I have a spread that is bound to a custom object collection.  The first column's datafield is set to the MonthName property of the object.  I would like for the cells in this column to be checkboxes with the caption the MonthName property.  It works fine if the cells are just of texttype but if i try to change the cell type at run time it makes all of the cells blank checkboxes. I have seen the threads where you tell them just to put all the cells to checkbox at design time but I have to set the cell type at run time because the number of rows will vary each time the spread is created.  Any suggestions?
  • Replied 8 September 2017, 12:29 pm EST

    Hello,


    Assuming the object you are binding to the Spread is something like the myobject class defined in the following example snipet, you can create a custom celltype class to implement what you are looking.

     
    Public Class mycombobox
    Inherits FarPoint.Win.Spread.CellType.GeneralCellType
    Dim x As New FarPoint.Win.Spread.CellType.CheckBoxCellType
    Dim c As New FarPoint.Win.FpCheckBox
    Dim mo As myobject

    Public Overrides Sub PaintCell(ByVal g As System.Drawing.Graphics, ByVal r As System.Drawing.Rectangle, ByVal appearance As FarPoint.Win.Spread.Appearance, ByVal value As Object, ByVal isSelected As Boolean, ByVal isLocked As Boolean, ByVal zoomFactor As Single)
    If Not value Is Nothing Then
    mo = CType(value, myobject)
    x.Caption = mo.Month
    x.PaintCell(g, r, appearance, mo.Checked, isSelected, isLocked, zoomFactor)
    Else
    MyBase
    .PaintCell(g, r, appearance, value, isSelected, isLocked, zoomFactor)
    End If
    End Sub

    Public Overrides Function
    IsReservedLocation(ByVal g As System.Drawing.Graphics, ByVal x As Integer, ByVal y As Integer, ByVal rc As System.Drawing.Rectangle, ByVal appearance As FarPoint.Win.Spread.Appearance, ByVal value As Object, ByVal zoomFactor As Single) As Object
    Return Me
    End Function

    Public Overrides Function
    GetEditorControl(ByVal appearance As FarPoint.Win.Spread.Appearance, ByVal zoomFactor As Single) As System.Windows.Forms.Control
    c.Caption = x.Caption
    c.BackColor = appearance.BackColor
    c.ForeColor = appearance.ForeColor
    c.Checked = mo.Checked
    Return c
    End Function

    Public Overrides Function
    GetEditorValue() As Object
    Dim
    moRet As New myobject
    moRet.Month = mo.Month
    moRet.Checked = c.checked
    Return moRet
    End Function
    End Class


    Public Class
    myobject
    Dim m_Month As String
    Dim
    m_Checked As Boolean

    Public Property
    Month() As String
    Get
    Return
    m_Month
    End Get
    Set
    (ByVal value As String)
    m_Month = value
    End Set
    End Property

    Public Property
    Checked() As Boolean
    Get
    Return
    m_Checked
    End Get
    Set
    (ByVal value As Boolean)
    m_Checked = value
    End Set
    End Property
    End Class
     
Need extra support?

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

Learn More

Forum Channels