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

    Hello,

     

    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;
                

                this.grid_Batch.TableElement.BeginUpdate();
                
                            
                try
                {
                    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();
                        val.Load(reader);                  
                        

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

                        grid_Batch.MasterTemplate.Columns.Add(batch);

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

                        grid_Batch.MasterTemplate.Columns.Add(comment);

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

                        grid_Batch.Columns.Add(created);

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

                        grid_Batch.MasterTemplate.Columns.Add(Frequency);

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

                        grid_Batch.Columns.Add(Status);

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

                        grid_Batch.MasterTemplate.Columns.Add(tran);

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

                        grid_Batch.MasterTemplate.Columns.Add(Total);

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

                        grid_Batch.MasterTemplate.Columns.Add(SOURCDOC);
                       
                        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!!!!!!!!!
                    
                    else
                        row[5].Value = "Available";       
                }
            }

     

    Thanks,

    Ed

  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;

    }

     

    Thanks,

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Dimitar
    Admin
    Dimitar avatar
    1415 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.
     
    Regards,
    Dimitar
    Telerik
    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