开发者

Datagrid View Dropdown list Event handler

开发者 https://www.devze.com 2023-01-30 01:05 出处:网络
I have added a dropdown column in DGridview but i am unable to generate event that shou开发者_Python百科ld fire when any value from dropdown menu is selected.

I have added a dropdown column in DGridview but i am unable to generate event that shou开发者_Python百科ld fire when any value from dropdown menu is selected. Here is the code for adding column

DataGridViewComboBoxColumn com = new DataGridViewComboBoxColumn();

            com.HeaderText = "";
            com.Items.Add( "Print Invoice");
            com.Items.Add("Print Job Card");            
            com.Items.Add("Close Job Card");            
            createCol = false;            
            ViewActiveJobs.Columns.Add(com);


Try this.You have to create new Event handler for Combobox and call that event in

EditingControlShowing .

 private void ViewActiveJobs_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)

    {

    comboBOX = (ComboBox)e.Control;

    comboBOX .SelectedIndexChanged -=new EventHandler(comboBOX _SelectedIndexChanged);
    comboBOX .SelectedIndexChanged +=new EventHandler(comboBOX _SelectedIndexChanged);

    }


    private void comboBOX _SelectedIndexChanged(object sender, EventArgs e)

    {

    ComboBox combo = sender as ComboBox;
    string str=combo.SelectedIndex.ToString();

    }
0

精彩评论

暂无评论...
验证码 换一张
取 消