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

[Solved] Implementing custom GridTextColumnEditor

1 Answer 96 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ignas
Top achievements
Rank 1
Ignas asked on 18 Jun 2009, 01:05 PM
I'm not sure I quite understand how the extension of GridTextColumnEditor goes, say I have extended the class like this:

public
 class CustomEditor : GridTextColumnEditor 
    private TextBox textBox; 
 
    protected override void LoadControlsFromContainer() 
    { 
        this.textBox = this.ContainerControl.Controls[0] as TextBox; 
    } 
    public override bool IsInitialized 
    { 
        get 
        { 
            return this.textBox != null
        } 
    } 
    public override string Text 
    { 
        get 
        { 
            return "salmon"
        } 
        set 
        { 
            this.textBox.Text = value; 
        } 
    } 
    protected override void AddControlsToContainer() 
    { 
        this.textBox = new TextBox(); 
        this.ContainerControl.Controls.Add(this.textBox); 
    } 
But the field still gets updated with the value entered in the textBox, instead of "salmon". Why is this? I want to implement a custom editor which consists of two TextBoxes, which contain the cell value splitted by the first whitespace character, and it returns the the value combined from the two TextBoxes.

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 22 Jun 2009, 04:16 PM
Hi Ignas,

How do you attach your column editor to your column? Here is an example using RadGrid's CreateColumnEditor event:

void RadGrid1_CreateColumnEditor(object sender, GridCreateColumnEditorEventArgs e) 
    if (e.Column is GridBoundColumn && (e.Column as GridBoundColumn).DataField == "PriceOnDate"
    { 
        e.ColumnEditor = new CustomEditor(); 
    } 

Also, in your overridden AddControlsToContainer() method you need to set an ID for your server text box. Otherwise you will get a "ViewState failed to load" exception on your page.

Regards,
Veli
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
Grid
Asked by
Ignas
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or