Error during ValueChanged for Checkbox

3 posts, 1 answers
  1. Stephane
    Stephane avatar
    27 posts
    Member since:
    Mar 2009

    Posted 23 Nov 2010 Link to this post


    Hi,
    I try to use the RadDataGridWiew to binding my collection of Object.

    I define 5 columns wich one is a checkboxcolumn.

    But when i click on the checkboxcell, the datagridwiew throw an exception "Data Exception".
    the error indicates that it's impossible to convert the value "Off" to boolean type.

    ???

    Best regards.
  2. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 23 Nov 2010 Link to this post

    Hello,

    In your object collection, you need to return a boolean for the checkbox column. Please try the following simple code exmaple (just a grid on a form) which should help to show how to add a checkbox column.

    Imports Telerik.WinControls.UI
    Imports Telerik.WinControls
      
    Public Class Form1
      
        Public Sub New()
            InitializeComponent()
        End Sub
      
      
        Private Sub Form1_Load(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles MyBase.Load
      
            Dim people As New List(Of Person)
            people.Add(New Person(1, "Richard", False))
            people.Add(New Person(1, "Bob", False))
            people.Add(New Person(1, "Peter", True))
            people.Add(New Person(1, "Stew", Nothing))
      
            Me.RadGridView1.AutoGenerateColumns = False
      
            Me.RadGridView1.Columns.Add(New GridViewDecimalColumn("Id", "Id"))
            Me.RadGridView1.Columns.Add(New GridViewTextBoxColumn("Name", "Name"))
            Me.RadGridView1.Columns.Add(New GridViewCheckBoxColumn("HasBeard", "HasBeard"))
      
            Me.RadGridView1.DataSource = people
      
        End Sub
      
      
    End Class
      
    Public Class Person
        Private m_Id As Integer
        Private m_Name As String
        Private m_HasBeard As Boolean
      
        Public Sub New(ByVal id As Integer, ByVal name As String, ByVal hasBeard As Boolean)
            m_Name = name
            m_Id = id
            m_HasBeard = hasBeard
        End Sub
      
        Public Property Name() As String
            Get
                Return m_Name
            End Get
            Set(ByVal value As String)
                m_Name = value
            End Set
        End Property
      
        Public Property Id() As Integer
            Get
                Return m_Id
            End Get
            Set(ByVal value As Integer)
                m_Id = value
            End Set
        End Property
      
        Public Property HasBeard() As Boolean
            Get
                Return m_HasBeard
            End Get
            Set(ByVal value As Boolean)
                m_HasBeard = value
            End Set
        End Property
      
    End Class


    If you need further help, please let me know.
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 23 Nov 2010 Link to this post

    Hello,

    Here is also a help article on GridViewCheckBoxColumn

    Let me know if you need further help
    Richard
Back to Top