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

radGrid bound to dataset : primary editable?

2 Answers 85 Views
Grid
This is a migrated thread and some comments may be shown as answers.
seriallabs
Top achievements
Rank 1
seriallabs asked on 28 Jan 2009, 04:49 PM
Hello, I've got a lot of issues with RadGrid. I suppose I don't use it in a standard way ?
Well, I have first a simple question:
I have some dataset created on the fly, and I link a radGrid to it. (to its first table)
One of the columns is a classic "Id" auto-inc primary key, which is set to ReadOnly

So when the user edits one row, I would like the "id" column ot be "not editable"
BUT the IsEditable property is a "get" property, which returns true ...

Relevant Code:
<telerik:RadGrid ID="RadGrid1" runat="server"   
            AllowSorting="True"   
               
            AutoGenerateDeleteColumn="True"   
            AutoGenerateEditColumn="True"             oncolumncreated="RadGrid1_ColumnCreated"   
            ondatabound="RadGrid1_DataBound"   
            onneeddatasource="RadGrid1_NeedDataSource"   
               
            onitemupdated="RadGrid1_ItemUpdated" onrowdrop="RadGrid1_RowDrop"   
            onupdatecommand="RadGrid1_UpdateCommand"   
            AllowMultiRowEdit="True"    
              
            > 
 
<MasterTableView DataKeyNames ="cID" EditMode="InPlace">  
... 
 if (mydt.PrimaryKey == null || mydt.PrimaryKey.Length<1)  
        { // if there is no primary  
            DataColumn col = new DataColumn("cID"typeof(int));  
            col.AutoIncrement = true;  
              
            mydt.Columns.Add(col);  
            int rc = 0;  
            foreach (DataRow drw in mydt.Rows){ rc++; drw["cID"] = rc;}//fill for existing rows  
            mydt.PrimaryKey = new DataColumn[] { mydt.Columns["cID"] };  
              
        }  
        
        nDS.Tables[0].Columns["cID"].ReadOnly = true;  
              
        RadGrid1.DataSource = nDS.Tables[0];  
        RadGrid1.AutoGenerateColumns = false;  
 
        GridBoundColumn boundColumn;  
        boundColumn = new GridBoundColumn();  
        RadGrid1.MasterTableView.Columns.Add(boundColumn);  
        boundColumn.DataField = "cID";  
        boundColumn.HeaderText= "id";  
 
        bool ised = boundColumn.IsEditable; //RETURNS TRUE ! 


bool
ised = boundColumn.IsEditable; // RETURNS TRUE !! and the corresponding field is shown while editing.

How to set the radGrid column to "not editable" so that no entry textbox is generated ?

Thank you!

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 29 Jan 2009, 04:18 AM
Hello Olivier,

Inorder to make a column non-editable, you can set the ReadOnly property of the column to true as shown below:
cs:
        GridBoundColumn boundColumn; 
        boundColumn = new GridBoundColumn(); 
        RadGrid1.MasterTableView.Columns.Add(boundColumn); 
        boundColumn.DataField = "cID"
        boundColumn.HeaderText = "id"
        boundColumn.ReadOnly = true

Thanks
Princy.
0
seriallabs
Top achievements
Rank 1
answered on 29 Jan 2009, 09:35 AM
Hello Princy,
Thank you so much.
it works perfectly. Actually, it was quite obvious. The fact is a did not see such property in the doc of radGrid, and have searched many hours in other directions..
Tags
Grid
Asked by
seriallabs
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
seriallabs
Top achievements
Rank 1
Share this question
or