hi there

how can i make the datadrid view edit and read, i have a button called edit when the user clicks it the cells can be editable ,or else the datagrid view in read only mode how can i change the modes in code, programatically


thaxxxxxxx

Recommended Answers

All 4 Replies

Set "EditMode" for the datagridview to "EditProgrammatically".

Use this for the "Edit" button:

dataGridView1.EditMode = DataGridViewEditMode.EditOnKeystrokeOrF2;

If you have a "Read Only" button the use this:

dataGridView1.EditMode = DataGridViewEditMode.EditProgrammatically;

Thanks

Set "EditMode" for the datagridview to "EditProgrammatically".

Use this for the "Edit" button:

dataGridView1.EditMode = DataGridViewEditMode.EditOnKeystrokeOrF2;

If you have a "Read Only" button the use this:

dataGridView1.EditMode = DataGridViewEditMode.EditProgrammatically;

Thanks

hey the think is when i am loading the data i made it to readonly mode but when i am going to add a new record the whole datagrid view goes in to write mode which allows the user to edit the ones that are displayed from the datbase only,

how can i make write only for the row i am adding only

thanxxxx

Okay. Add "CellBeginEdit" event for the dgv and do something like this:

private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
   {
            int rowThatShouldBeEdited = 2;
            if (e.RowIndex != rowThatShouldBeEdited)
                e.Cancel = true;
   }

Thanks

Okay. Add "CellBeginEdit" event for the dgv and do something like this:

private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
   {
            int rowThatShouldBeEdited = 2;
            if (e.RowIndex != rowThatShouldBeEdited)
                e.Cancel = true;
   }

Thanks

farooqaaa:

it dosen't work for me. what i want it when the datais begin added to the form when loading i want them to be read only but the forst column which is in a check box column that shold be in write mode.

Question 1:
in the form load i added the code line u have posted for read only, but the thing is all the cells are in readonly, how can i make the first column write only.

Question2:
and also when i click on that datagridview combo box column i need to make the whole row to editable mode,

how can i do this.

i tried in several ways but i couldn't do it with the information you had given.

Question3:
also i added the CellBeginEdit with the one u have posted it didn't work for me, so i tried and add some code but it didn't also work,the code is below

private void dgvDAction_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            int rowThatShouldBeEdited = dgvDAction.CurrentRow.Index;
            if (e.RowIndex == rowThatShouldBeEdited)
                dgvDAction.EditMode = DataGridViewEditMode.EditProgrammatically;//read write
            else
                dgvDAction.EditMode = DataGridViewEditMode.EditProgrammatically;// read only
        }

thanxxxxxxxxxx

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.