We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Mouse click on Checkbox check column gives error 'System.Data.DataException' Cannot check [Columnname]

Hello,
I added the checkbox column first and then added set DataSource to a datatable.
Now the issue is when I try to click the checkbox, it gives me error.

please find the image with this post which consist of code.

Following is my code : 

Private Sub btnGO_Click(sender As Object, e As EventArgs) Handles btnGO.Click
        Try
            dgvGrid.TableSummaryRows.Clear()
            Dim sdt As New DataTable
            sdt.Rows.Clear() : sdt.Columns.Clear()
#Region "DATA QUERY sdt datatable gets data in here"
            sdt = DtBound("DATA QUERY HERE", con1) ' dtbound fetches data from query from sql server and return it to datatable

#End Region
            dgvGrid.Columns.Clear()
            dgvGrid.Columns.Add(New GridCheckBoxColumn() With {.MappingName = "CHECK", .HeaderText = String.Empty, .AllowThreeState = True, .AllowText = False, .AllowCheckBoxOnHeader = True})
            dgvGrid.DataSource = sdt
            ' Creates the GridSummaryColumn1.
            Dim summaryColumn1 As New GridSummaryColumn()
            summaryColumn1.Name = "namt"
            summaryColumn1.Format = "{Sum:c}"
            summaryColumn1.MappingName = "NET AMOUNT"
            summaryColumn1.SummaryType = SummaryType.DoubleAggregate


            'TableSummary Row
            Dim tableSummaryRow1 As New GridTableSummaryRow
            tableSummaryRow1.Name = "TableSummary"
            tableSummaryRow1.ShowSummaryInRow = False
            tableSummaryRow1.Position = VerticalPosition.Bottom
            tableSummaryRow1.SummaryColumns.Add(summaryColumn1)
            dgvGrid.TableSummaryRows.Add(tableSummaryRow1)


            dgvGrid.Style.TableSummaryRowStyle.HorizontalAlignment = HorizontalAlignment.Right


 


        Catch ex As Exception
            ErrDisplay(ex) : MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

Following error I face: 

System.Data.DataException

  HResult=0x80131920

  Message=Cannot set CHECK.

  Source=System.Data

  StackTrace:

   at System.Data.DataRowView.set_Item(String property, Object value)

   at Syncfusion.Data.ItemPropertiesProvider.SetDataTableView(Object record, String propName, Object value)

   at Syncfusion.Data.ItemPropertiesProvider.SetValue(Object record, String propName, Object value)

   at Syncfusion.WinForms.DataGrid.Data.DataGridItemsPropertiesProvider.SetValue(Object record, String propName, Object value)

   at Syncfusion.WinForms.DataGrid.Renderers.GridCheckBoxCellRenderer.ChangeCheckBoxValue(DataColumnBase dataColumn, RowColumnIndex rowColumnIndex, CheckState state)

   at Syncfusion.WinForms.DataGrid.Renderers.GridCheckBoxCellRenderer.OnMouseUp(DataColumnBase dataColumn, RowColumnIndex rowColumnIndex, MouseEventArgs e)

   at Syncfusion.WinForms.DataGrid.Renderers.GridCellRendererBase.MouseUp(DataColumnBase dataColumn, RowColumnIndex rowColumnIndex, MouseEventArgs e)

   at Syncfusion.WinForms.DataGrid.GridHandler.OnMouseUp(Object sender, MouseEventArgs e)

   at System.Windows.Forms.MouseEventHandler.Invoke(Object sender, MouseEventArgs e)

   at System.Windows.Forms.Control.OnMouseUp(MouseEventArgs e)

   at Syncfusion.WinForms.Controls.SfScrollControl.OnMouseUp(MouseEventArgs e)

   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)

   at System.Windows.Forms.Control.WndProc(Message& m)

   at Syncfusion.WinForms.Controls.SfScrollControl.WndProc(Message& msg)

   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)

   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)

   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)

   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)

   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()

   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()

   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)

   at myproject.My.MyApplication.Main(String[] Args) in :line 81



1 Reply

SJ Sathiyathanam Jeyakumar Syncfusion Team April 20, 2023 12:02 PM UTC

Hi Urvik,

Upon investigation of the reported problem, we have determined that the scenario is not an issue. However, we have discovered that the GridCheckBoxColumn with the MappingName "CHECK" is being used, but this property is not present in the underlying datasource. As a result, the checkbox value cannot be changed. To prevent the reported exception from occurring, we recommend adding the "CHECK" property to your underlying datasource ie.Add “CHECK” property to your DataTable Columns. Once this is done, the checkbox value can be modified as needed.

DataTable employeeCollection;

Public Sub New()

    InitializeComponent()

    Me.StartPosition = FormStartPosition.CenterScreen

    Me.sfDataGrid1.AutoGenerateColumns = False

    Dim table = Me.GetDataTable()

    sfDataGrid1.DataSource = table

    sfDataGrid1.AllowEditing = True

    Me.sfDataGrid1.SelectionMode = GridSelectionMode.Multiple

    Me.sfDataGrid1.Columns.Add(New GridCheckBoxColumn() With {

        .MappingName = "CHECK"

    })

    Me.sfDataGrid1.Columns.Add(New GridTextColumn() With {

        .MappingName = "OrderID",

        .HeaderText = "Order ID"

    })

    Me.sfDataGrid1.Columns.Add(New GridTextColumn() With {

        .MappingName = "CustomerID",

        .HeaderText = "Customer ID",

        .ColumnMemberType = GetType(String)

    })

    Me.sfDataGrid1.Columns.Add(New GridTextColumn() With {

        .MappingName = "CustomerName",

        .HeaderText = "Customer Name"

    })

    Me.sfDataGrid1.Columns.Add(New GridTextColumn() With {

        .MappingName = "Country",

        .HeaderText = "Country"

    })

    Me.sfDataGrid1.Columns.Add(New GridTextColumn() With {

        .MappingName = "ShipCity",

        .HeaderText = "Ship City"

    })

End Sub

 

Public Function GetDataTable() As DataTable

    employeeCollection = New DataTable()

    employeeCollection.Columns.Add("OrderID", GetType(Integer))

    employeeCollection.Columns.Add("CustomerID", GetType(String))

    employeeCollection.Columns.Add("CustomerName", GetType(String))

    employeeCollection.Columns.Add("Country", GetType(String))

    employeeCollection.Columns.Add("ShipCity", GetType(String))

    employeeCollection.Columns.Add("CHECK", GetType(Boolean))

    employeeCollection.Rows.Add(1001, "ALFKI", "Maria Anders", "Germany", "Berlin")

    employeeCollection.Rows.Add(1002, "ANATR", "Ana Trujilo", "Mexico", "Mexico D.F.")

    employeeCollection.Rows.Add(1003, "ANTON", "Antonio Moreno", "Mexico", "Mexico D.F.")

    employeeCollection.Rows.Add(1004, "AROUT", "Thomas Hardy", "UK", "London")

    employeeCollection.Rows.Add(1005, "BERGS", "Christina Berglund", "Sweden", "Lula")

   

    Return employeeCollection

End Function


Let us know if you need any further assistance on this.

Regards

Sathiyathanam


Loader.
Up arrow icon