FarPoint Forums

The FarPoint Message Boards
Welcome to FarPoint Forums Sign in | Join | Help
in Search

Difficulty with ListBox control in custom cell type

Last post 10-07-2008, 5:38 AM by BobM. 1 replies.
Sort Posts: Previous Next
  •  10-07-2008, 4:36 AM 69968

    Difficulty with ListBox control in custom cell type

    Hi,

    I want to put a listbox control into a custom celltype. The code I have is as follows:

    For the spread:

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="cellTest1.aspx.vb" Inherits="cellTest1" %>

    <%@ Register Assembly="FarPoint.Web.Spread" Namespace="FarPoint.Web.Spread" TagPrefix="FarPoint" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >

    <head runat="server">

    <title>Untitled Page</title>

    </head>

    <body>

    <form id="form1" runat="server">

    <div>

    <farpoint:fpspread id="FpSpread1" runat="server" bordercolor="Black" borderstyle="Solid"

    borderwidth="1px" height="200" width="400"><CommandBar ButtonShadowColor="ControlDark" ButtonFaceColor="Control" ButtonHighlightColor="ControlLightLight" BackColor="Control"></CommandBar><Sheets><FarPoint:SheetView SheetName="Sheet1"></FarPoint:SheetView></Sheets></farpoint:fpspread>

     

    </div>

    </form>

    </body>

    </html>

     

    In the code behind:

    Partial Class cellTest1

    Inherits System.Web.UI.Page

    Sub makeCell()

    Dim theCell As FarPoint.Web.Spread.Cell

    Dim customCell As New listType

    theCell = FpSpread1.Cells(0, 0)

    theCell.CellType = customCell

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    makeCell()

    End Sub

    End Class

    In the listType class

    Imports Microsoft.VisualBasic

    <Serializable()> Public Class listType

    Inherits FarPoint.Web.Spread.GeneralCellType

    Public Overrides Function PaintCell(ByVal id As String, ByVal parent As System.Web.UI.WebControls.TableCell, ByVal style As FarPoint.Web.Spread.Appearance, ByVal margin As FarPoint.Web.Spread.Inset, ByVal value As Object, ByVal upperLevel As Boolean) As System.Web.UI.Control

     

    Dim dmSpread As FarPoint.Web.Spread.SheetView

    Dim ctl As Control = parent.Parent

    While Not TypeOf ctl Is FarPoint.Web.Spread.FpSpread

    ctl = ctl.Parent

    End While

    dmSpread = CType(ctl, FarPoint.Web.Spread.FpSpread).Sheets(0)

    Try

    If Not dmSpread Is Nothing Then

    Dim c As Control = MyBase.PaintCell(id, parent, style, margin, value, upperLevel)

    Dim qualificationTypesListBox As ListBox = CType(c, ListBox)

    qualificationTypesListBox.Items.Add("Doctoral Degree")

    qualificationTypesListBox.Items.Add("Masters Degree")

    qualificationTypesListBox.Items.Add("Bachelors Degree")

    Return qualificationTypesListBox

    End If

     

    Catch ex As Exception

    End Try

    End Function

     

    When I load the page I get the error Value cannot be Null. Parameter name: Child. Clearly I must be passing a null value somewhere but I'm not sure where. Can anyone shed any light?

    Nick

  •  10-07-2008, 5:38 AM 69970 in reply to 69968

    Re: Difficulty with ListBox control in custom cell type

    Nick -

    I received other errors than the one you specified.  I modified your code to the following and it works...

    <Serializable()> Public Class listType

    Inherits FarPoint.Web.Spread.GeneralCellType

    Dim list As New ListBox



    Public Overrides Function PaintCell(ByVal id As String, ByVal parent As System.Web.UI.WebControls.TableCell, ByVal style As FarPoint.Web.Spread.Appearance, ByVal margin As FarPoint.Web.Spread.Inset, ByVal value As Object, ByVal upperLevel As Boolean) As System.Web.UI.Control

    Dim dmSpread As FarPoint.Web.Spread.SheetView

    Dim ctl As Control = parent.Parent

    While Not TypeOf ctl Is FarPoint.Web.Spread.FpSpread

    ctl = ctl.Parent

    End While

    dmSpread = CType(ctl, FarPoint.Web.Spread.FpSpread).Sheets(0)

    If Not dmSpread Is Nothing Then
    list.Items.Add("Doctoral Degree")
    list.Items.Add("Masters Degree")
    list.Items.Add("Bachelors Degree")


    End If
    Return list
    End Function

    End Class


    Bob M.
    FarPoint Technologies, Inc.
View as RSS news feed in XML
     FarPoint Forums Home