Custom combobox edit column template

3 posts, 1 answers
  1. solutionfactory
    solutionfactory avatar
    45 posts
    Member since:
    Apr 2007

    Posted 30 Oct 2008 Link to this post

    Hi all,
    i have a problem with my custom edit column template.

    This is my column
            public class MyEnumColumnEditor : GridTextColumnEditor 
            { 
                private RadComboBox box; 
                private readonly Type enumType; 
                private readonly bool useDescription = false
                private readonly bool addTopEmptyItem = false
     
     
                public MyEnumColumnEditor(Type enumType, bool useDescription, bool addTopEmptyItem) 
                { 
                    this.enumType = enumType; 
                    this.useDescription = useDescription; 
                    this.addTopEmptyItem = addTopEmptyItem; 
                } 
     
                protected override void AddControlsToContainer() 
                { 
                    this.box = new RadComboBox(); 
     
                    ArrayList list = new ArrayList(); 
                    Array enumValues = Enum.GetValues(enumType); 
                    Type baseType = Enum.GetUnderlyingType(enumType); 
     
                    if (addTopEmptyItem) 
                        list.Add(new KeyValuePair<intstring>(-1, string.Empty)); 
     
                    foreach (Enum value in enumValues) 
                    { 
                        string desc = useDescription ? Data.GetEnumDescription(value) : value.ToString(); 
                        list.Add(new KeyValuePair<intstring>((int)Convert.ChangeType(value, baseType), desc)); 
                    } 
     
                    this.box.DataSource = list; 
                    this.box.DataTextField = "Value"
                    this.box.DataValueField = "Key"
                    this.box.DataBind(); 
                    this.box.SelectedIndex = 0; 
                     
                    this.ContainerControl.Controls.Add(this.box); 
                } 
     
                protected override void LoadControlsFromContainer() 
                { 
                    this.box = this.ContainerControl.Controls[0] as RadComboBox; 
                } 
     
                public override bool IsInitialized 
                { 
                    get 
                    { 
                        return this.box != null
                    } 
                } 
     
                public override string Text 
                { 
                    get 
                    { 
                        if (this.box.SelectedItem == null
                            return string.Empty; 
     
                        return this.box.SelectedValue; 
                    } 
                    set  
                    { 
                        this.box.SelectedIndex = string.IsNullOrEmpty(value) ? 0 :  
                                               this.box.FindItemIndexByValue(value); 
                    } 
                } 
     
            } 
     

    All works fine, but when i edit an existing item, the selected item displayed on combobox is not the current value.

    The SelectedIndex is correctly but the displayed item is always the first.

    Any suggestion?

    Thanks in advance,
    Flavio



  2. Answer
    Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2285 posts

    Posted 03 Nov 2008 Link to this post

    Hello Flavio,

    Please find the project attached to this forum post. It demonstrates how you must implement custom column editor. The links below will give you a detailed information about how grid editors works and how to extend them.

    Custom editors extending auto-generated editors
    Using grid server-side API for extraction

    I hope that helps.

    Best wishes,
    Nikolay
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. solutionfactory
    solutionfactory avatar
    45 posts
    Member since:
    Apr 2007

    Posted 03 Nov 2008 Link to this post

    Hello Nikolay,
    works as expected for me,
    thank a lot.

    Best regards,
    Flavio
Back to Top