RadGrid Combobox column Item not in list

4 posts, 0 answers
  1. Joan Adams
    Joan Adams avatar
    6 posts
    Member since:
    Mar 2005

    Posted 29 Apr 2008 Link to this post

    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.
  2. Georgi
    Admin
    Georgi avatar
    212 posts

    Posted 01 May 2008 Link to this post

    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
  3. Adam
    Adam avatar
    12 posts
    Member since:
    Apr 2011

    Posted 01 Feb 2012 Link to this post

    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...
    }
  4. Ivan Petrov
    Admin
    Ivan Petrov avatar
    705 posts

    Posted 06 Feb 2012 Link to this post

    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 >>
Back to Top