'Insert checkbox in each column of a datagriview in VB.net
I am trying to code-build a checkbox in my calendar datagridview.
With the following stored procedure I am building the calendar SQL SERVER
SET LANGUAGE Español
set @PERIODO = @PERIODO
declare @columnas varchar(max)= ''
select @columnas = coalesce(@columnas + '[' + cast(DIAS as varchar(12)) + '],', '')
FROM (Select c.NombreDiaCorto+CONVERT(varchar(2),c.DIA) AS DIAS
From AUT_CALENDARIO c
--where @FechaInicio<=c.FECHA and c.FECHA<=@FechaFin
where @PERIODO=substring(c.IDCALENDARIO,1,6)
) as DTM
set @columnas = left(@columnas,LEN(@columnas)-1)
--Select @columnas
DECLARE @SQLString nvarchar(MAX);
set @SQLString = N'
SELECT TOP 1 *
into TEMP_CALENDARIO
FROM
(Select 0 as X, c.NombreDiaCorto+CONVERT(varchar(2),c.DIA) AS DIAS
from AUT_CALENDARIO c
CROSS APPLY AUT_PERSONAL p
where substring(c.IDCALENDARIO,1,6)='''+ @PERIODO+'''
) AS TABLA
PIVOT
(
MAX(X)
FOR DIAS IN (' + @columnas + ')
) AS PivotTable;'
--SELECT @SQLString
EXECUTE SP_EXECUTESQL @SQLString
--UPDATE T SET T.IDCODIGOGENERAL='' FROM TEMP_CALENDARIO T
Select * FROM TEMP_CALENDARIO
IF OBJECT_ID('TEMP_CALENDARIO') IS NOT NULL BEGIN drop table TEMP_CALENDARIO END
And I am displaying it in my datagridview with the following code snippet.
Sub listar_periodos()
Try
Me.dgvdias.DataSource = negHor.Listar_Calendarios(VGlobales.Base, Me.cboperiodo.SelectedValue)
Catch ex1 As SqlClient.SqlException : MessageBox.Show(ex1.Message, "MENSAJES", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Catch ex As Exception : MessageBox.Show(ex.Message, "MENSAJES", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
And it is displayed as follows, so far so good
But what I need is to replace the "0" with a checkbox control and thus allow me to select the day that I want, and quite apart to obtain the name of the column or the position that I have selected but so far I have not found the function or the logic of how to insert a checkbox any ideas or suggestions.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

