santBart
santBart

Reputation: 2496

c# readonly DataGridView with one enabled cell

I have readonly datagridview, I need in some specific case enable one cell after doubleclicking row (make readonly=false and make focus on this specific cell in current row (like entering it - the cursor should start to blink).

I have:

 private void dataGridView1_DoubleClick(object sender, EventArgs e)
{
       dataGridView1.Cells[3].ReadOnly = false;
}

But it doesn't work. Why?

Upvotes: 2

Views: 9945

Answers (2)

Danny
Danny

Reputation: 21

dataGridView1 ReadOnly property should be set to false. each row ReadOnly property should be set to true. then you can set the cell ReadOnly to true when required.

//setting each row

    foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    row.ReadOnly = true;
                }

//setting on cell

    DataGridViewCell cell = dataGridView1.Rows[e.RowIndex].Cells[3];
    dataGridView1.CurrentCell = cell;
    dataGridView1.CurrentCell.ReadOnly = false;                
    dataGridView1.BeginEdit(true); 

Upvotes: 2

Stelian Matei
Stelian Matei

Reputation: 11623

Try to set the currentcell of the Datagridview and call BeginEdit

 private void dataGridView1_DoubleClick(object sender, EventArgs e)
 {
    dataGridView1.Cells[3].ReadOnly = false;
    this.dataGridView1.CurrentCell = dataGridView1.Cells[3];
    dataGridView1.BeginEdit(true);
}

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.beginedit.aspx

Upvotes: 1

Related Questions