This is a migrated thread and some comments may be shown as answers.
How to apply simple hardcoded combobox selection of days of week drop down when user clicks to edit a cell
1 Answer 5 Views
This is a migrated thread and some comments may be shown as answers.
Lyle
Top achievements
Rank 2
Lyle asked on 19 Jun 2020, 03:59 PM

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;
            }
        }

1 Answer, 1 is accepted

Sort by
0
Todor Vyagov
Telerik team
answered on 22 Jun 2020, 03:18 PM

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.
Asked by
Lyle
Top achievements
Rank 2
Answers by
Todor Vyagov
Telerik team
Share this question
or