jeudi 29 juillet 2021

How to add dynamically control when checkbox in datagridview is checked vb.net

I tired for this
How to add dynamically textbox, label, and form from checkbox in datagridview?

this is my code

Sub getDataWIP()
    dgvbool = False
    D_DATA.Columns.Clear()
    Dim dt As DataTable = getData("SELECT created_at AS 'TANGGAL', assy_code AS 'ASSY CODE', model AS 'MODEL', lot_no AS 'LOT NUMBER',  " &
                                   "remark AS 'REMARK', qty AS QTY, shift AS SHIFT, pic AS PIC " &
                                   "FROM WIP_AUTO")
    D_DATA.DataSource = dt
    Dim checkBoxColumn As New DataGridViewCheckBoxColumn()
    checkBoxColumn.HeaderText = ""
    checkBoxColumn.Width = 30
    checkBoxColumn.Name = "checkBoxColumn"
    D_DATA.Columns.Insert(0, checkBoxColumn)
    dgvbool = True
End Sub

and this

Private Sub P_PRINT_Click(sender As Object, e As EventArgs) Handles P_PRINT.Click
    Template.Show()
    Dim message As String = String.Empty
    For Each row As DataGridViewRow In D_DATA.Rows
        Dim isSelected As Boolean = Convert.ToBoolean(row.Cells("checkBoxColumn").Value)
        If isSelected Then
            message += Environment.NewLine
            message += row.Cells("MODEL").Value.ToString()
            Dim txt As New Label
            txt.Text = row.Cells("MODEL").Value
            txt.Location = New Point(50, 50)
            Template.Controls.Add(txt)
        End If
    Next
End Sub



Aucun commentaire:

Enregistrer un commentaire