I'm having a problem in my DataGridViewLinkColumn
. When specific columnIndex
clicked, I want to change the link column text. (please see example below)
In example above, I want to change the text(the highlighted one) that is clicked to SAVE.
NOTE: the changing must be done only in specific row and column index
I used datagridViewColumn
and here's my code: (link column displays when bind in datatable then display to datagrid.)
Dim da As New SqlDataAdapter("SELECT DateReq AS [Date Requested],NoHrs AS [# OT Hrs.],status,approved_by FROM tableName" _
& "WHERE requested_by='" & lbluserid.Text & "'" _
& " ORDER BY date_request ASC", Constr)
Dim dt As New DataTable
ds.Clear()
da.Fill(dt)
dg.DataSource = dt
dg.Columns.Add(lnkEdit)
lnkEdit.HeaderText = ""
lnkEdit.Name = "edit"
lnkEdit.Text = "Edit"
lnkEdit.UseColumnTextForLinkValue = True
dg.Columns(4).Width = 45
dg.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter
dg.Columns.Add(lnkCancel)
lnkCancel.HeaderText = ""
lnkCancel.Name = "cancel"
lnkCancel.Text = "Cancel"
lnkCancel.UseColumnTextForLinkValue = True
dg.Columns(5).Width = 45
dg.Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter
Just handle the CellContentClick event, get the right cell and set it's value:
Note that your problem is that a
DataGridViewLinkCell
either displays it'sValue
(whenUseColumnTextForLinkValue == false
), or it displays theText
of it'sDataGridViewLinkColumn
(whenUseColumnTextForLinkValue == true
).So if you want to change the text of the link at runtime you'll have to set
UseColumnTextForLinkValue = false
, and fill the cells beforehand with the textEdit
, e.g. something like: