Sunday, May 6, 2012

C# Windows Form add combo box controller selected index change event

In this post i will explain how to add combo box  selectedIndexChage event. Add gridview controller to Form , then add DataGridViewComboboxColumn to gridview and DataGridviewTextboxColumn.

then Create EditingControlSowing event as follow and add following code into source


 private void testgrid_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            ComboBox cmbBox;
            if ( testgrid .CurrentCell.ColumnIndex == 0)
            {
                cmbBox = e.Control as ComboBox;
                if (cmbBox == null)
                    return;
                cmbBox.SelectedIndexChanged += cmbBox_SelectedIndexChanged;
            }
        }



        void cmbBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox cmbBox = (ComboBox)sender;

            string getvalue= ((ComboBox)sender).SelectedValue.ToString();
            string setvalue= obClass.Sampkemethod( getvalue );

           testgrid .Rows[stockadjustmentgrid.CurrentCell.RowIndex].Cells[1].Value =  setvalue ;
         
        }

in above code what happen is, gather DataGridViewEditingControlShowingEventArgs  and it assign to new combobox controller .after that we create new selectedindex chage event for our new ComboBox and assign value that gathter according ComboBox selected value and , assign it to next textbox column.

No comments:

Post a Comment