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

custom column breaks in DetailTables

4 Answers 115 Views
Grid
This is a migrated thread and some comments may be shown as answers.
matt
Top achievements
Rank 1
matt asked on 04 Sep 2008, 06:51 PM
hello,

since the RadGrid columns have no simple property for "IsRequired" (which would make data-entry required in edit mode), i had to write my own custom column classes. they work in MasterTableViews. cool.

but, they dont work when used in DetailTables. when i use this:

<Nola:RequiredGridBoundColumn UniqueName="Name" HeaderText="Name" DataField="Name" MaxLength="50" /> 

i get this:

You must override Clone() for a derived grid column.

why is this?

here is the source code:

namespace CustomTelerikExtensions 
    /// <summary>   
    /// An extended GridBoundColumn that requires users to enter data into the GridBoundColumn's TextBox. 
    /// </summary>   
    public class RequiredGridBoundColumn : GridBoundColumn 
    { 
        public override void InitializeCell(TableCell cell, int columnIndex, GridItem gridItem) 
        { 
            base.InitializeCell(cell, columnIndex, gridItem); 
 
            // if in edit mode && the editor is not null 
            if (gridItem.IsInEditMode && cell.Controls[0] != null
            { 
                //assign ID of the default editor, if it is empty or null   
                if (!Strings.Exists(cell.Controls[0].ID)) 
                    cell.Controls[0].ID = String.Format("{0}_TextBox"this.DataField); 
 
                //add new required-field-validator 
                RequiredFieldValidator requiredValidator = new RequiredFieldValidator(); 
 
                requiredValidator.ID = gridItem.OwnerGridID + "_RequiredFieldValidator" + columnIndex; 
                requiredValidator.ControlToValidate = cell.Controls[0].ID; 
                requiredValidator.Text = "&nbsp;Required"
                requiredValidator.CssClass = "required"
 
                string message = String.Format("\"{0}\" cannot be empty."this.HeaderText); 
                requiredValidator.ErrorMessage = message; 
                requiredValidator.ToolTip = message; 
 
                //add validator to the cell 
                cell.Controls.Add(requiredValidator); 
            } 
        } 
 
        //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
 
        public override GridColumn Clone() 
        { 
            return base.Clone(); 
        } 
    } 




thanks,
matt

4 Answers, 1 is accepted

Sort by
0
matt
Top achievements
Rank 1
answered on 15 Sep 2008, 11:37 PM
telerik - what is up w/ this??

thanks
0
Rosen
Telerik team
answered on 16 Sep 2008, 06:29 AM
Hi matt,

Basically you should create new instance of the current column and copy the current column's settings' values to the new one. This is necessary for the correct creation of the detail tables.

Best wishes,
Rosen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
matt
Top achievements
Rank 1
answered on 16 Oct 2008, 04:49 PM
rosen,

i dont understand what you mean. can you please be more specific when replying -- eg, provide code examples?


thanks,
matt
0
Rosen
Telerik team
answered on 17 Oct 2008, 03:57 PM
Hi matt,

As I stated in my previously message, you should created new column of the current column's type, copy the current column's properties and return the newly created column, similar to the following:

        public override GridColumn Clone()  
        {  
            RequiredGridBoundColumn requiredGridBoundColumn = new RequiredGridBoundColumn();  
            //you should override CopyBaseProperties if you have some column specific properties  
            requiredGridBoundColumn.CopyBaseProperties(this);  
 
            return requiredGridBoundColumn;  
        } 

 
All the best,
Rosen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
matt
Top achievements
Rank 1
Answers by
matt
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or