Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > GridView > RadGrid Combobox column Item not in list

Not answered RadGrid Combobox column Item not in list

Feed from this thread
  • Joan Adams avatar

    Posted on Apr 29, 2008 (permalink)

    I have a radgrid with a combobox column that I need to allow the user to type in, and if the item they enter is not in the list, allow them to add it to the underlying datasource via another form.

    I would like to know which event to handle on the radgrid or combocolumn that will allow me to do this.

    It is super easy to do using, name kept secret, control suite, via a method called ItemInList. Alas, I cannot find a similar solution in the Telerik suite. Please tell me that I am just overlooking it.


    Thanks in advance.

    Reply

  • Georgi Georgi admin's avatar

    Posted on May 1, 2008 (permalink)

    Hi Joan Adams,

    Thank you for sharing your ideas.

    Although there is no such feature in the GridViewComboBoxColumn (GridViewLookUpColumn) out-of-the-box, you still can implement the behavior in your custom code. When an edit operation is finished and the new value is to be saved in the grid, the RadGridView.Validating event is fired. You could attach to it to check whether the corresponding column is currently edited and if it is so, you can get the new value through RadGridView.ActiveEditor.Value. After that, you can check if it exists in the underlaying data source and take the necessary actions.

    Another way to do this is to use the RadGridView.CellEditorInitialized and RadGridView.CellEndEdit events. In the event handler for the RadGridView.CellEditorInitialized, attach to the RadGridView.ActiveEditor.Validating event. Then, in the event handler for editor's Validating event you could do the same actions. In this approach, you should remember to detach from editor's Validating event when it is closed in the event handler for CellEndEdit event.

    Please try one or both of these approaches and tell us if it works fine for you. Also if you have any additional questions, please don't hesitate to write us.

    Regards,
    Georgi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

    Reply

  • Adam avatar

    Posted on Feb 1, 2012 (permalink)

    Hi, I have the same issue as the original poster, but neither of those options seem to work...

    Here is the basic setup....
    private BindingList<String> applicants;
     
    public NewReceiptSplitWizard(String receiptNumber)
    {
        applicants = new BindingList<String>();
        applicants.Add("");
     
        GridViewComboBoxColumn applicant = (GridViewComboBoxColumn)otherDGV.Columns["otherApplicantDGVCBC"];
        applicant.DataSource = applicants;
    }

    Here is solution 1 impelmented:
    void otherDGV_CellValidating(object sender, CellValidatingEventArgs e)
    {
        if (e.Column.Name.Equals("otherApplicantDGVCBC"))
        {
            object o = e.ActiveEditor.Value;  // this is NULL!!!!!
            String applicantName = (string)e.Value;
            if (!applicants.Contains(applicantName))
            {
                applicants.Add(applicantName);
                e.Cancel = false;
                return;
            }
        }
    }


    Here is Solution 2 impelemented:
    void otherDGV_CellEditorInitialized(object sender, GridViewCellEventArgs e)
    {
        if (e.Column.Name.Equals("otherApplicantDGVCBC"))
        {
            otherDGV.ActiveEditor.Validating +=new CancelEventHandler(ActiveEditor_Validating); // tapped directly into the DGV.ActiveEditor
                     
            RadDropDownListEditor editor = e.ActiveEditor as RadDropDownListEditor;
            if (editor != null)
            {
                //editor.Validating += new CancelEventHandler(editor_Validating); // I even tried this since acessing the dgv directly didn't work
             }
        }
    }
     
    void ActiveEditor_Validating(object sender, CancelEventArgs e)
    {
        int i = 1; // this code never executes...
    }

    Reply

  • Ivan Petrov Ivan Petrov admin's avatar

    Posted on Feb 6, 2012 (permalink)

    Hello Adam,

    Thank you for writing and for the provided code snippets.

    You can look at the following help article which describes how to achieve this scenario - Allow end-users to add items to DropDownListEditor

    I hope you will find this useful. Should you have further questions, feel free to ask.

    Greetings,
    Ivan Petrov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > GridView > RadGrid Combobox column Item not in list
Related resources for "RadGrid Combobox column Item not in list"

[ Features | Demos | Documentation | Knowledge Base | Telerik TV | Code Library | Step-by-step Tutorial | Blogs | Self-Paced Trainer ]