复选框始终返回False vb.net

时间:2017-02-15 15:18:20

标签: vb.net datagridview

我想在我检查DatagridView中的复选框时显示消息“True”,但它总是显示“False”我正在寻找解决方案这是我的代码

    Try
        'opening the connection
        con.Open()
            If row.Cells(15).FormattedValue = False Then
                'store your delete query to a variable(sql)
                sql = "DELETE FROM terres WHERE id = '" _
                            & CStr(row.Cells(3).FormattedValue) & "'"
                MsgBox(row.Cells(3).FormattedValue)
                'Set your MySQL COMMANDS
                With cmd
                    .Connection = con
                    .CommandText = sql
                End With
                'Execute the Data
                result = cmd.ExecuteNonQuery
            End If
        Next
        'the condition is, if the result is equals to zero
        'then the message will appear and says "No Deleted Record."
        'and if not the message will appear and says "The Record(s) has been deleted.."
        If result = 0 Then
            MsgBox("No Deleted Record.")
        Else
            MsgBox("The Record(s) has been deleted.")
        End If
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
    'Close the connection
    con.Close()

1 个答案:

答案 0 :(得分:0)

在构建DataTable / DataGridView时,请尝试使用以下复选框列:

dtdgv.Columns.Add("Process", GetType(Boolean))
'More columns etc.
'Seriously look at table adapters and 
'make SURE they wont work for your application
'Fill dtdgv
DataGridView1.DataSource = dtdgv
DataGridView1.Refresh()

然后在确定是否检查时:

For Each row As DataGridViewRow In DataGridView1.Rows
    If row.Cells("Process").Value = True Then
        'Stuff
    End If    
Next

你正在寻找什么?