Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have populated a datagridview using a sqldatareader / datatable which is having 3 columns.
Further I want to edit 3rd column in datagridiew. Though it is allowing editing in 1st column but not in 2nd & 3rd column. Plz help. Here is snippet of my code.
VB
Private Sub cmdGetName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGetName.Click
    Dim sqlcmd As New SqlCommand, reader As SqlDataReader, dTable As New DataTable
    sqlcmd.Connection = cnRM
    sqlcmd.CommandText = "select * from RMPARAS"
    cnRM.Open()
    reader = sqlcmd.ExecuteReader
    If reader.HasRows Then
        dTable.Load(reader)
        dgv.DataSource = dTable
        For Each column In dgv.Columns
            column.SortMode = DataGridViewColumnSortMode.NotSortable
        Next
        dgv.ReadOnly = False
        dgv.Refresh()
        cnRM.Close()
    End If
End Sub

Private Sub dgv_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv.CellClick
    dgv.CurrentCell.ReadOnly = False
    dgv.BeginEdit(False)
End Sub



Exception thrown is

Error happened : Context : Commit : Exception : System.Data.ReadOnlyException: Column 'VALUE' is read only.
at System.Data.DataRow.set_Item(DataColumn column, Object value)
at System.Data.DataRowView.SetColumnValue(DataColumn column, Object value)
at System.Data.DataColumnPropertyDescriptor.SetValue(Object component, Object value)
at System.Windows.Forms.DataGridView.DataGridViewDataConnection.PushValue(Int32 boundColumnIndex, Int32 columnIndex, Int32 rowIndex, Object value)
Posted
Updated 19-Oct-13 21:14pm
v4

1 solution

This exception is thrown when you try and change the value of a readonly[^] column.

Here[^] is a guide that will make you troubleshoot this problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900