How do I set the initial value for a dropdown?

2 posts, 0 answers
  1. David
    David avatar
    8 posts
    Member since:
    May 2008

    Posted 16 Aug 2011 Link to this post

    I have a dropdownlist editor as a column. I have loaded it with the values "", "s", "m"

    I have an object that has an "s" stored in it...when I initialize the editor I would like to load the initial value that the object has in it....but I can't get it to work. The value of the cell is always null even after I set it.

    Thoughts?

    private void rgcSoil_CellEditorInitialized(object sender, GridViewCellEventArgs e)
            {
                if (e.Column.Name != "colSorM")
                    return;
     
                RadDropDownListEditor editor = e.ActiveEditor as RadDropDownListEditor;
                if (editor != null)
                {
                    var ee = (RadDropDownListEditorElement)((RadDropDownListEditor)this.rgcSoil.ActiveEditor).EditorElement;
                    ee.BeginEdit();
                    ee.DataSource = new String[] {"", "S", "M" };
                    SoilType st = (SoilType)e.Row.Tag;
     
                    ee.Value = st.StandardOrModified;
                    ee.EndEdit();
                }
            }
  2. Stefan
    Admin
    Stefan avatar
    2908 posts

    Posted 19 Aug 2011 Link to this post

    Hello David,

    Thank you for writing.

    I am not sure I fully understand your scenario. If you want to have different data sources for each row of GridViewComboBoxColumn, please refer to the following KB article. Otherwise, if the binding is OK and you just want to set the value of the active editor, you can do that with the following code in the CellEditorInitialized event handler:
    e.ActiveEditor.Value= st.StandardOrModified;

    I hope that you find this information helpful. Should you have any other questions, do not hesitate to contact us.
     
    Kind regards,
    Stefan
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Back to Top