Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Combobox in Datagridview

$
0
0

i have gridview with two combo boxes in it . While selecting the first value of it on first selection, it is not getting . But for second time of selection it is getting . my code is below , please check it

  private void productGrid_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (e.Control is DataGridViewComboBoxEditingControl)
            {
                ((ComboBox)e.Control).DropDownStyle = ComboBoxStyle.DropDown;
                ((ComboBox)e.Control).AutoCompleteSource = AutoCompleteSource.ListItems;
                ((ComboBox)e.Control).AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
                ((ComboBox)e.Control).DropDownWidth = 100;
            }
            if (productGrid.CurrentCell.ColumnIndex == 1 && e.Control is ComboBox)
            {
                ComboBox comboBox = e.Control as ComboBox;
                if (comboBox.SelectedValue != null)
                {
                    comboBox.SelectedIndexChanged += LastColumnComboSelectionChanged;
                }
            }
            if (e.Control is DataGridViewTextBoxEditingControl)
            {
                var txtEdit = (TextBox)e.Control;
                txtEdit.KeyDown += EditKeyPress;
            }
        }
        private void LastColumnComboSelectionChanged(object sender, EventArgs e)
        {
            var currentcell = productGrid.CurrentCellAddress;

            var sendingCB = sender as DataGridViewComboBoxEditingControl;
            string pid;
            try
            {
                pid = Convert.ToString(sendingCB.SelectedValue);
                if (pid != null)
                {

                    DataGridViewComboBoxCell ComboColumn = (DataGridViewComboBoxCell)(productGrid.CurrentRow.Cells[1]);
                    if (productGrid.CurrentRow.Cells[1].Value == null)
                    {
                        productGrid.CurrentCell.Selected = true;
                        //isinGridview = false;
                    }

                }
            }
            catch (Exception)
            {

            }


Viewing all articles
Browse latest Browse all 31927


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>