Within my program i have included a datagridview that is filled when the form loads. When it first loads i have set the whole form to read-only. However if the user then wants to edit the data within it they can click an edit button i have included on the form, this has the code:
datagrdSnippets.AllowUserToDeleteRows = True 'Allows user to delete rows
datagrdSnippets.ReadOnly = False 'Allows user to edit cells within the data grid
However i do not want one of the columns within the datagridview to be made editable, what code can i use to do this?
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Column1.ReadOnly = True
Column2.ReadOnly = True
Column3.ReadOnly = True
End Sub
set readonly true your desired column on form load event
Me, I have data source from database in my dataGridView so I use for loop to get the exact column address that I want to make ReadOnly=true and the rest is ReadOnly=false
Code:
For i = datagridview1.columns.count - 1 to 0 Step -1
If i = (YourSpecificColumnAddress) Then
Datagridview1.columns(i).ReadOnly=true
Else
Datagridview1.columns(i).ReadOnly=false
End if
Next
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With