Okay I have a datagridview with multiple rows and columns of data. I set the grid to Readonly == true by default, but have a method that when the user double clicks the datagridview, it's gets the current cell the user is clicking and then uses this line of code

dataGridView1 [locX, locY].ReadOnly = false;

What I want it to do, is when the user double clicks the selected cell it will allow me to edit the current cell (also the reason I don't have readonly off, is because some columns I don't want to be allowed to edit and I don't want the user to accidently click a square and editing it when they don't mean to, that's why I add the double click in)

7 Years
Discussion Span
Last Post by JOSheaIV

Have a look:

DataTable dt = new DataTable();

            dt.Rows.Add(1, "A");
            dt.Rows.Add(2, "B");

            dataGridView1.RowsAdded += (sa, ea) =>
                    if (ea.RowCount==1)
                        DataGridViewRow r = dataGridView1.Rows[ea.RowIndex];
                        r.ReadOnly = true  ;
            dataGridView1.CellMouseDoubleClick  += (sa, ea) =>
                dataGridView1[ea.ColumnIndex, ea.RowIndex].ReadOnly = false ;
            dataGridView1.CellEndEdit += (sa, ea) =>
                dataGridView1[ea.ColumnIndex, ea.RowIndex].ReadOnly = true;
            dataGridView1.DataSource = dt;

Hmm I will have to try this when I get home from work, but let me ask you a quick question.

What does the datasource line do?
What does "=>" do?


You know what no response, so for now I am just saying screw it and went with an old way I wrote the code. I need to pick up the pace on this program so for now I'll put this idea on ice

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.