The DataGridViewCell
inherits the ReadOnly
property from its owning column or row. Setting the property to True
means you can't use the cell's EditingControl
to change the value and it's only can be changed by code.
You can instead set the DataGridView.EditMode
property to DataGridViewEditMode.EditProgrammatically
to disable putting the cells in edit mode by the mouse and key inputs. By code in the CellContentClick
event handler, select and put a given cell in edit mode when you click the link cell of the selected row.
Example to put the Qty
cell in edit mode.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DataGridView2.DataSource = itrservice.GetLoadStocksoutdetailMaster()
DataGridView2.EditMode = DataGridViewEditMode.EditProgrammatically
End Sub
Private Sub DataGridView2_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView2.CellContentClick
If e.ColumnIndex = 4 Then
DataGridView2.CurrentCell = DataGridView2(3, e.RowIndex)
DataGridView2.BeginEdit(True)
End If
End Sub
You can use the columns Name
property to identify them instead of the index..
Private Sub DataGridView2_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView2.CellContentClick
If DataGridView2.Columns(e.ColumnIndex) Is DataGridView2.Columns("coledit") Then
DataGridView2.CurrentCell = DataGridView2("Qty", e.RowIndex)
DataGridView2.BeginEdit(True)
End If
End Sub
Another example on how you should populate the grid and add the DataGridViewLinkColumn
.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DataGridView2.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect
DataGridView2.EditMode = DataGridViewEditMode.EditProgrammatically
DataGridView2.DataSource = itrservice.GetLoadStocksoutdetailMaster().ToList()
DataGridView2.Columns.Add(New DataGridViewLinkColumn With {
.Name = "coledit",
.Text = "Edit",
.HeaderText = "",
.UseColumnTextForLinkValue = True,
.TrackVisitedState = False
})
' Optional...
DataGridView2.Columns("coledit").DefaultCellStyle.SelectionBackColor = Grid.Columns("coledit").DefaultCellStyle.BackColor
End Sub
Side note, IMO the FullRowSelect
is not appropriate SelectionMode
here. Use the default RowHeaderSelect
value instead.