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

Custom GridView ComboBox Column Event

1 Answer 329 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Usman
Top achievements
Rank 2
Usman asked on 05 Sep 2013, 11:43 AM
Heloo, 
I have added a combo box column programmatically with a static data source.
Now i need that whenever i select any of the item a specific function should be invoked.
I have tried with different events but didnt found a solution.
Please Help
var dg = new GridViewComboBoxColumn
               {
                   DataSource = new[] { "Edit", "Delete" },
                   HeaderText = "Action",
                   Name = "col_Action",
                   Width = 80,
                   AllowResize = true,
                   FieldName = "gv_cmb_Action",
                   SortOrder = RadSortOrder.None,
                   AllowFiltering = false,
                   AllowGroup = false,
                   AllowSort = false,
                   ReadOnly = false
               };
 
            if (gv_Criteria.ColumnCount != 9)
            {
                gv_Criteria.Columns.Insert(8, dg);
            }

1 Answer, 1 is accepted

Sort by
0
Accepted
Nikolay
Telerik team
answered on 10 Sep 2013, 11:36 AM
Hello Usman,

If I understand your requirement correctly, you want to execute some functions the moment you change the selection in the drop-down, without closing the editor. If this is the case, you should subscribe to the CellBeginEdit event of RadGridView in order to access the editor, and then subscribe to the SelectedIndexChanged event of the editor:

this.gv_Criteria.CellBeginEdit += new GridViewCellCancelEventHandler(gv_Criteria_CellBeginEdit);
 
void gv_Criteria_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
{
    if (e.Column.Name == "col_Action")
    {
        ((RadDropDownListEditorElement)((RadDropDownListEditor)e.ActiveEditor).EditorElement).SelectedIndexChanged -= new Telerik.WinControls.UI.Data.PositionChangedEventHandler(Form1_SelectedIndexChanged);
        ((RadDropDownListEditorElement)((RadDropDownListEditor)e.ActiveEditor).EditorElement).SelectedIndexChanged += new Telerik.WinControls.UI.Data.PositionChangedEventHandler(Form1_SelectedIndexChanged);
    }
}
 
void Form1_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
    RadDropDownListEditorElement editor = sender as RadDropDownListEditorElement;
    if (editor != null)
    {
        if (editor.SelectedItem != null)
        {
            if (editor.SelectedItem.Text == "Edit")
            {
                Console.WriteLine("Edit Function");
            }
            else if (editor.SelectedItem.Text == "Delete")
            {
                Console.WriteLine("Delete Function");
            }
        }
    }
}

Note that for optimization purposes we are caching and reusing the same RadDropDownListEditor, so you need first to unsubscribe from the event before subscribing to it again.

I hope this helps.Regards,
Nikolay
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Usman
Top achievements
Rank 2
Answers by
Nikolay
Telerik team
Share this question
or