DataGridView Cell Editable

remya1000

Well-known member
Joined
Mar 29, 2007
Messages
122
Programming Experience
Beginner
I’m using VB.Net.

I’m using DataGridView with ColumnType = DataGridViewTextBoxColumn.

I have 3 columns. Column1, Column2, Column3.

For example:
VB.NET:
Column1          Column2          Column3
1                        AA                AAA
2                        BB                EDIT
3                        CC                CCC

If column3’s value = “EDIT”, then I need to edit only that cell.

Here for example: i need to make the Column3’s second cell to be readonly=false.

So i cannot make any changes to (1, AA, AAA), (3, CC, CCC) and (2, BB). Need to make changes only EDIT cell.

I tried this code. CountR is the row in which EDIT values is there.

VB.NET:
DataGridView1.Item(2, CountR).ReadOnly = False
VB.NET:
DataGridView1.Rows(CountR).Cells(2).ReadOnly = False

But this makes every cell in column editable.

Is there a way i can make some cells editable in column?

If you know how to do it, please help me. if you can provide an example, then that will be so helpful.

Thanks in Advance.
 
Setting ReadOnly property of the cells would be the way to go.
 
Thanks JohnH for the reply.

DataGridView1.Rows(CountR).Cells(2).ReadOnly = False

i tried the above code for setting Readonly property of the cell. but this makes every cell in that column editable.

If you know how to do this, please help me.

Thanks in advance.
 
i tried the above code for setting Readonly property of the cell. but this makes every cell in that column editable.
Setting a single cell to ReadOnly won't affect other cells, so that is not true.
 
johnH, thank you so much for your help.

As you said i think i'm executing that code multiple times with different row indexes.

So i try this code, and it's working...

VB.NET:
                For Each r As DataGridViewRow In DataGridView1.Rows
                    If r.Cells(3).Value.ToString = "EDIT" Then
                        r.Cells(3).ReadOnly = False
                    Else
                        r.Cells(3).ReadOnly = True
                    End If
                Next

Thank you so much for your help.....
 
Back
Top