How to apply simple hardcoded combobox selection of days of week drop down when user clicks to edit a cell

2 posts, 0 answers
  1. Lyle
    Lyle avatar
    1 posts
    Member since:
    Jun 2020

    Posted 19 Jun Link to this post

    I'm new to Telerik and still working on the 30 day trial so please bear with me, and pardon the ignorance if this is mind numbingly simple,

     

    I need a simple way to show a simple hardcoded dropdown (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday) which validates input when a user edits the cell of a RadGridView

          private void dg_DeliverySched_beginEdit(object sender, Telerik.WinControls.UI.GridViewCellCancelEventArgs e)
            {
                //I have these columns that need day of week validation comboboxes on edit click
                if (e.Row is GridViewFilteringRowInfo && e.Column.Name == "Sun")
                {
                    e.Cancel = true;
                }
                if (e.Row is GridViewFilteringRowInfo && e.Column.Name == "Mon")
                {
                    e.Cancel = true;
                }
                if (e.Row is GridViewFilteringRowInfo && e.Column.Name == "Tue")
                {
                    e.Cancel = true;
                }
                if (e.Row is GridViewFilteringRowInfo && e.Column.Name == "Wed")
                {
                    e.Cancel = true;
                }
                if (e.Row is GridViewFilteringRowInfo && e.Column.Name == "Thu")
                {
                    e.Cancel = true;
                }
                if (e.Row is GridViewFilteringRowInfo && e.Column.Name == "Fri")
                {
                    e.Cancel = true;
                }
                if (e.Row is GridViewFilteringRowInfo && e.Column.Name == "Sat")
                {
                    e.Cancel = true;
                }
            }

  2. Todor Vyagov
    Admin
    Todor Vyagov avatar
    44 posts

    Posted 22 Jun Link to this post

    Hi Lyle,

    Thank you for writing.

    If you are using GridViewTextBoxColumn you can subscribe to the EditorRequired event and substitute the TextBoxEditor with a RadDropDownListEditor. After this subscribe to the CellEditorInitialized event and set up the desired values of the combo editor:

    this.radGridView1.EditorRequired += this.RadGridView1_EditorRequired;
    this.radGridView1.CellEditorInitialized += this.RadGridView1_CellEditorInitialized;
    
    private void RadGridView1_EditorRequired(object sender, EditorRequiredEventArgs e)
    {
        if (this.radGridView1.CurrentColumn.Name == "Day")
        {
            e.EditorType = typeof(RadDropDownListEditor);
        }
    }
    
    private void RadGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
    {
        if (this.radGridView1.CurrentColumn.Name == "Day")
        {
            RadDropDownListEditor comboBoxEditor = e.ActiveEditor as RadDropDownListEditor;
            if (comboBoxEditor != null)
            {
                RadDropDownListElement element = (RadDropDownListElement)comboBoxEditor.EditorElement;
                element.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDownList;
                element.DataSource = new List<string>() { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
                element.SelectedValue = e.Value;
            }
        }
    }
    

    The result is illustrated in the picture below:


    More information about RadGridView editors is available here:  https://docs.telerik.com/devtools/winforms/controls/gridview/editors/editors

    I hope this information helps. If you need further assistance please do not hesitate to contact me.

    Regards,
    Todor Vyagov
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
Back to Top