GridView Read only cell

3 posts, 0 answers
  1. edson
    edson avatar
    4 posts
    Member since:
    Mar 2015

    Posted 15 Dec 2015 Link to this post



    I have an radgridview that its bound to an datatable from code behind. From code I setup columns and from designer I have one checkbox column.

    When I run the app and mark that checkbox column I want to change the text value of one of the other columns. But when I try to change the value of the other column it say "Column "name" its readonly." I check the status of the cell and its says readonly = false;

     private void BindGrid()


    var result = SqlClass.JT_Batch_GetBatches();

                grid_Batch.MasterTemplate.AllowAddNewRow = false;
                this.grid_Batch.AutoGenerateColumns = false;
                this.grid_Batch.AllowEditRow = true;
                this.grid_Batch.MasterTemplate.AllowAddNewRow = false;
                this.grid_Batch.MasterTemplate.AutoGenerateColumns = false;
                this.grid_Batch.MasterTemplate.AllowEditRow = true;
                this.grid_Batch.MasterTemplate.AllowDeleteRow = false;
                this.grid_Batch.MasterTemplate.AllowCellContextMenu = false;
                this.grid_Batch.MasterTemplate.ShowFilterCellOperatorText = false;
                this.grid_Batch.MasterTemplate.ShowHeaderCellButtons = true;
                this.grid_Batch.MasterTemplate.EnableFiltering = false;
                this.grid_Batch.EnableFiltering = true;
                this.grid_Batch.MasterTemplate.ShowFilteringRow = false;

                    using (SqlConnection conn = SqlClass.GetConnection())
                        SqlCommand cmd = new SqlCommand();
                        cmd.CommandText = "GetBatches";
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Connection = conn;

                        SqlDataReader reader = cmd.ExecuteReader();
                        DataTable val = new DataTable();

                       GridViewTextBoxColumn batch = new GridViewTextBoxColumn("Batch");
                        batch.Width = 161;
                        batch.ReadOnly = true;


                        GridViewTextBoxColumn comment = new GridViewTextBoxColumn("Comment");
                        comment.Width = 215;
                        comment.ReadOnly = true;


                        GridViewDateTimeColumn created = new GridViewDateTimeColumn("Created");
                        created.Width = 86;
                        created.ReadOnly = true;


                        GridViewTextBoxColumn Frequency = new GridViewTextBoxColumn("Frequency");
                        Frequency.Width = 129;
                        Frequency.ReadOnly = true;


                        GridViewTextBoxColumn Status = new GridViewTextBoxColumn("Status");
                        Status.Width = 139;
                        Status.ReadOnly = false;


                        GridViewDecimalColumn tran = new GridViewDecimalColumn("# Tran.");
                        tran.Width = 60;
                        tran.ReadOnly = true;


                        GridViewDecimalColumn Total = new GridViewDecimalColumn("Total");
                        Total.Width = 82;
                        Total.ReadOnly = true;
                        Total.FormatString = "{0:$#,###0.00;($#,###0.00);0}";


                        GridViewTextBoxColumn SOURCDOC = new GridViewTextBoxColumn("SOURCDOC");
                        SOURCDOC.Width = 0;
                        SOURCDOC.ReadOnly = true;
                        SOURCDOC.IsVisible = false;

                        this.grid_Batch.DataSource = val.DefaultView;


    private void grid_Batch_CellEndEdit(object sender, GridViewCellEventArgs e)
                if (e.Column.Name == "select")
                    var row = grid_Batch.CurrentRow.Cells;                                                         
                    GridViewCellInfo cell = row[5] as GridViewCellInfo;

                    if (bool.Parse(row["select"].Value.ToString()) == true)
                        cell.Value = "MArked"; //HERE I GET THE ERROR MESSAGE!!!!!!!!!
                        row[5].Value = "Available";       




  2. edson
    edson avatar
    4 posts
    Member since:
    Mar 2015

    Posted 15 Dec 2015 in reply to edson Link to this post

    I resolve the my problem by doing this before assing the datasource property to gridview.


    foreach(DataColumn col in DataTable.Columns)


    col.ReadOnly = false;




  3. Dimitar
    Dimitar avatar
    2960 posts

    Posted 16 Dec 2015 Link to this post

    Hello Edson,

    Thank you for writing.

    All columns which are read-only in the data table will be read-only in the grid as well. And your solution is correct, if you want to make changes, you should set the read-only property of the columns to false.

    Do not hesitate to contact us if you have other questions.
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top