This is a migrated thread and some comments may be shown as answers.

RadGrid Combobox column Item not in list

3 Answers 252 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Joan Adams
Top achievements
Rank 1
Joan Adams asked on 29 Apr 2008, 06:07 PM
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.

3 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 01 May 2008, 11:24 AM
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
0
Adam
Top achievements
Rank 1
answered on 01 Feb 2012, 09:11 PM
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...
}
0
Ivan Petrov
Telerik team
answered on 06 Feb 2012, 10:47 AM
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 >>
Tags
GridView
Asked by
Joan Adams
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Adam
Top achievements
Rank 1
Ivan Petrov
Telerik team
Share this question
or