judithSampathwa -2 Posting Pro in Training

hi there,

i have a datagrid view with a combo box and 3 datagrid view text boxes in the datagrid view.when the form is loaded the value to the datagrid view ocmbo box is loaded. when u select on a value from the datagrid view combo box the relevant details will be loaded. and also i need the same datagrid view combo box to be editable when i try to begin editing, the values in the relevant datagrid view cells should be blank. i have the code below but it is not working properly.

private void dgvSubContract_CurrentCellDirtyStateChanged(object sender, EventArgs e)
        {
            if (dgvSubContract.CurrentCell == null)
                return;
           
              

                 if ((dgvSubContract.CurrentCell.Value != null))  
                {
                     dgvSubContract.CommitEdit(DataGridViewDataErrorContexts.Commit); 
                     if (dgvSubContract.CurrentCell.ColumnIndex == 0)
            {
                    int r = dgvSubContract.CurrentCell.RowIndex;
                                       
                    String subName = dgvSubContract.Rows[r].Cells[0].Value.ToString();
                    String[] a = new String[4];

                    a = m.getSudDetails(subName);

                    dgvSubContract.Rows[r].Cells[1].Value = a[0].ToString();
                    dgvSubContract.Rows[r].Cells[2].Value = a[1].ToString();
                    dgvSubContract.Rows[r].Cells[3].Value = a[2].ToString();
                    dgvSubContract.Rows[r].Cells[4].Value = a[3].ToString();
                    dgvSubContract.Rows[r].Cells[1].ReadOnly = true;
                    dgvSubContract.Rows[r].Cells[1].ReadOnly = true;
                    dgvSubContract.Rows[r].Cells[1].ReadOnly = true;
                    dgvSubContract.Rows[r].Cells[1].ReadOnly = true;
                }

            }

        }

        private void dgvSubContract_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            int r = dgvSubContract.SelectedCells[0].RowIndex;
            if (!String.IsNullOrEmpty(string.Format("" + dgvSubContract.Rows[r].Cells[0].Value)))
                dgvSubContract.ClearSelection();
            else
            {
                DataGridViewComboBoxEditingControl comboControl = e.Control as DataGridViewComboBoxEditingControl;
                if (comboControl != null)
                {
                    // Set the DropDown style to get an editable ComboBox
                    if (comboControl.DropDownStyle != ComboBoxStyle.DropDown)
                    {
                        comboControl.DropDownStyle = ComboBoxStyle.DropDown;
                    }

                }
            }

        }

        private void dgvSubContract_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            if (!String.IsNullOrEmpty(string.Format("" + dgvSubContract.Rows[0].Cells[0].Value)))
            {
                int r = dgvSubContract.CurrentCell.RowIndex;
                dgvSubContract.Rows[r].Cells[1].Value = "";
                dgvSubContract.Rows[r].Cells[2].Value = "";
                dgvSubContract.Rows[r].Cells[3].Value = "";
                dgvSubContract.Rows[r].Cells[4].Value = "";
            }
        }

thanxxxxxxxx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.