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

How to make my checkbox column only editable in radgridview ?

7 Answers 895 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ragupathi
Top achievements
Rank 1
Ragupathi asked on 08 Sep 2008, 10:04 AM


I have added the one checkbox colum in the grid. I would like to make that column editbale and rest of the columns are not. how to make it ?, At the same time I want to capture the  checkbox state changed event.

FYI : I am using the following code to add checkbox column

GridViewCheckBoxColumn
checkBoxColumn = new GridViewCheckBoxColumn();

checkBoxColumn.DataType =

typeof(bool);

checkBoxColumn.HeaderText =

string.Empty;

checkBoxColumn.Width = 25;

dGridDisplayField.MasterGridViewTemplate.Columns.Insert(0, checkBoxColumn);

Thanks you
Raghu

7 Answers, 1 is accepted

Sort by
0
Accepted
Jack
Telerik team
answered on 09 Sep 2008, 07:02 AM
Hello Ragupathi,

Thank you for contacting us.

You should set the ReadOnly property of all columns except the check box column to true. This will make them not editable.

As for capturing value-change event I suggest you to use the ValueChanged event of RadGridView to capture changes in grid values. Consider the following code snippet:

void grid_ValueChanged(object sender, EventArgs e) 
    if (this.grid.ActiveEditor is RadCheckBoxEditor) 
    { 
        bool value = (bool)this.grid.ActiveEditor.Value; 
    } 


I hope this helps.

All the best,
Jack
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Ragupathi
Top achievements
Rank 1
answered on 25 Nov 2008, 08:32 AM
Hi,
Thanks for your Answer.
I have one more question regarding this.
I am not able set the the Header Text empty for this Check box column. If I set HeaderText = String.Empty, the value is not relfelecting.
Coming as Column1, if I set some other text the setted value is coming in the header.

Thanks
Raghu
 
0
Jack
Telerik team
answered on 25 Nov 2008, 03:14 PM
Hello Ragupathi,

Thank you for this question.

RadGridView uses the value of the UniqueName property as a default header text when the HeaderText is empty. You should set the HeaderText to a nonempty string (e.g. space) to override this behavior. Consider the following code:

this.radGridView1.Columns["Value"].HeaderText = " "

I hope this helps. Do not hesitate to write us if you have other questions.

Best wishes,
Jack
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Chris
Top achievements
Rank 1
answered on 19 Jun 2009, 05:57 AM
Hi I have this code to add a checkbox column in a radgrid but still it is not enable so I can check and Uncheck it.

Please help

 

 

GridCheckBoxColumn checkColumn = new GridCheckBoxColumn();

 

checkColumn.DataField =

"Selected";

 

checkColumn.DataType =

typeof(bool);

 

checkColumn.ReadOnly =

false ;

 

checkColumn.HeaderText =

" ";

 

RadGrid1.MasterTableView.Columns.Add(checkColumn);

0
Jack
Telerik team
answered on 19 Jun 2009, 12:11 PM
Hi Chris,

I can't find any issues by looking at your code which to cause the issue you experience. Please open a support ticket and send me your application in order to investigate your case and locate the problem.

I am looking forward to your reply.

Sincerely yours,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Chris
Top achievements
Rank 1
answered on 22 Jun 2009, 08:51 AM
Hi Jack,

Here's my code. I want to enable the checkbox so I can select and unselect it.

ASPX page


<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MailingDetailsUc.ascx.cs" 
    Inherits="SampleTelerik.MailingDetailsUc" %> 
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
    Namespace="System.Web.UI" TagPrefix="asp" %> 
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
<asp:ScriptManager ID="ScriptManager1" runat="server">  
</asp:ScriptManager> 
<telerik:RadGrid ID="RadGrid1" runat="server">  
</telerik:RadGrid> 
 
 


Code Behind Code
 protected void Page_Load(object sender, EventArgs e)  
        {  
            DataTable table = new DataTable();  
 
            GridCheckBoxColumn checkColumn = new GridCheckBoxColumn();  
            checkColumn.DataField = "Selected";  
            checkColumn.DataType = typeof(bool);  
            checkColumn.ReadOnly = false;  
            checkColumn.HeaderText = "";  
            RadGrid1.MasterTableView.Columns.Add(checkColumn);  
 
            table.Columns.Add("Selected", typeof(Boolean));  
            table.Columns.Add("Title", typeof(string));  
 
            table.Rows.Add(1,"Record 1");  
            table.Rows.Add(0,"Record 2");  
            table.Rows.Add(1, "Record 3");  
            table.Rows.Add(0, "Record 4");  
            table.Rows.Add(1, "Record 5");  
 
            RadGrid1.DataSource = table;  
            RadGrid1.DataBind();  
        } 

0
Sebastian
Telerik team
answered on 22 Jun 2009, 11:20 AM
Hello Chris,

For this purpose you can use either GridClientSelectColumn to check/select grid records or a template column with checkbox inside its ItemTemplate. Review the following online demos of the product for more details:

http://demos.telerik.com/aspnet-ajax/grid/examples/client/selecting/defaultcs.aspx
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/selectrowwithcheckbox/defaultcs.aspx

Additionally, I recommend you use advanced binding with NeedDataSource event handling:
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/needdatasource/defaultcs.aspx

instead of simple binding with DataBind() calls. Also note that there are conventions for runtime grid creation which has to be followed to ensure that the viewstate/lifecycle of the control will be consistent.

Kind regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Ragupathi
Top achievements
Rank 1
Answers by
Jack
Telerik team
Ragupathi
Top achievements
Rank 1
Chris
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or