judithSampathwa -2 Posting Pro in Training

hi there, i have a datagrid view which has a combo box and 3 datagrid view text boxes.when the form loads the values form the database adds to the datagrid view combo box. when a value is selected the relevant information is begin taken from the database and displayed in the other datagrid view text boxes.
what i want to do is if there is no that is relevant to select the user should be able to add to the datagrid view by editing the datagrid view combo box,

how can i make the datagrid view editable in one click so that the user is able to write on the datagrid view combo box and the other datagrid view text boxes.

in the form load i add the below code to display data in the datagrid view ocmbo box

//Display the names of the subcontractors name in the datagrid view subcontractor tab
            dgvSubContract.Rows.Add();
            DataGridViewComboBoxColumn comboBox = (DataGridViewComboBoxColumn)dgvSubContract.Rows[0].Cells[0].OwningColumn;
            comboBox.Items.Clear();
            comboBox.Items.AddRange(m.FillSubContractName());

CurrentCellDirtyStateChanged method

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);
                    if (a[1] != null)
                    {
                        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[2].ReadOnly = true;
                        dgvSubContract.Rows[r].Cells[3].ReadOnly = true;
                        dgvSubContract.Rows[r].Cells[4].ReadOnly = true;
                    }
                    else
                    {
                        dgvSubContract.Rows[r].Cells[1].Value = "";
                        dgvSubContract.Rows[r].Cells[2].Value = "";
                        dgvSubContract.Rows[r].Cells[3].Value = "";
                        dgvSubContract.Rows[r].Cells[4].Value = "";
                        dgvSubContract.Rows[r].Cells[1].ReadOnly = false;
                        dgvSubContract.Rows[r].Cells[2].ReadOnly = false;
                        dgvSubContract.Rows[r].Cells[3].ReadOnly = false;
                        dgvSubContract.Rows[r].Cells[4].ReadOnly = false;
                    }
                }

            }

        }

if the user is trying to edit the other values in the datagrid view text boxes should be cleared how can i do this????????


thanxxxxxxxxx

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.