Custom GridView ComboBox Column Event

2 posts, 1 answers
  1. Usman
    Usman avatar
    3 posts
    Member since:
    Sep 2013

    Posted 05 Sep 2013 Link to this post

    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);
                }
  2. Answer
    Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 10 Sep 2013 Link to this post

    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 >>
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top