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.

     
    <SPAN class=kwd>Public Class</SPAN> mycombobox
    <SPAN class=kwd>Inherits</SPAN> FarPoint.Win.Spread.CellType.GeneralCellType
    <SPAN class=kwd>Dim</SPAN> x <SPAN class=kwd>As New</SPAN> FarPoint.Win.Spread.CellType.CheckBoxCellType
    <SPAN class=kwd>Dim</SPAN> c <SPAN class=kwd>As New</SPAN> FarPoint.Win.FpCheckBox
    <SPAN class=kwd>Dim</SPAN> mo <SPAN class=kwd>As</SPAN> myobject

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

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

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

    Public Overrides Function</SPAN> GetEditorValue() <SPAN class=kwd>As Object
    Dim</SPAN> moRet <SPAN class=kwd>As New</SPAN> myobject
    moRet.Month = mo.Month
    moRet.Checked = c.checked
    <SPAN class=kwd>Return</SPAN> moRet
    <SPAN class=kwd>End Function
    End Class


    Public Class</SPAN> myobject
    <SPAN class=kwd>Dim</SPAN> m_Month <SPAN class=kwd>As String
    Dim</SPAN> m_Checked <SPAN class=kwd>As Boolean

    Public Property</SPAN> Month() <SPAN class=kwd>As String
    Get
    Return</SPAN> m_Month
    <SPAN class=kwd>End Get
    Set</SPAN>(<SPAN class=kwd>ByVal</SPAN> value <SPAN class=kwd>As String</SPAN>)
    m_Month = value
    <SPAN class=kwd>End Set
    End Property

    Public Property</SPAN> Checked() <SPAN class=kwd>As Boolean
    Get
    Return</SPAN> m_Checked
    <SPAN class=kwd>End Get
    Set</SPAN>(<SPAN class=kwd>ByVal</SPAN> value <SPAN class=kwd>As Boolean</SPAN>)
    m_Checked = value
    <SPAN class=kwd>End Set
    End Property
    End Class</SPAN>
     
Need extra support?

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

Learn More

Forum Channels