This is a migrated thread and some comments may be shown as answers.

GridView Read only cell

2 Answers 642 Views
GridView
This is a migrated thread and some comments may be shown as answers.
edson
Top achievements
Rank 1
edson asked on 15 Dec 2015, 05:03 PM

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 Answers, 1 is accepted

Sort by
0
edson
Top achievements
Rank 1
answered on 15 Dec 2015, 09:05 PM

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,

Steven
Top achievements
Rank 1
commented on 15 Feb 2023, 08:29 PM

Thank you @edson !!!  Sometimes we miss the obvious :)
0
Dimitar
Telerik team
answered on 16 Dec 2015, 11:39 AM
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
Tags
GridView
Asked by
edson
Top achievements
Rank 1
Answers by
edson
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or