无法检查datagridview中的复选框? [英] Unable to check a checkbox in a datagridview?

查看:83
本文介绍了无法检查datagridview中的复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

I have the following code:

Private Sub holidaysaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles holidaysaveButton.Click
    For Each dr As DataGridViewRow In DataGridView1.Rows
      Dim cell1 As String
      Dim cell2 As Date
      Dim cell3 As String
      Dim cell4 As String = "Holiday"

      If dr.IsNewRow Then Exit For

      If dr.Cells(4).Value = "True" Then
        Dim str1 As String = dr.Cells(1).Value.ToString
        Dim str2 As String = dr.Cells(2).Value.ToString
        Dim str3 As String = dr.Cells(3).Value.ToString
        Dim str4 As String = dr.Cells(4).Value.ToString
      End If
      If dr.Cells(4).Value IsNot Nothing Then
        cell1 = dr.Cells(1).Value.ToString()
        cell2 = dr.Cells(2).Value.ToString()
        cell3 = dr.Cells(3).Value.ToString()
        Dim con As New SqlConnection
        Dim cmd As New SqlCommand
        Try
          con.ConnectionString = "Data Source=xxxxx;Initial Catalog=xxxxx;User ID=xxxxx;Password=xxxxx"
          con.Open()
          cmd.Connection = con
          cmd.CommandText = "INSERT INTO exceptions (employeenumber, exceptiondate, minutes, code) VALUES ('" & cell1 & "','" & cell2 & "','" & cell3 & "','" & cell4 & "')"
          cmd.ExecuteNonQuery()
          MessageBox.Show("Your data has been updated")
        Catch ex As Exception
          MessageBox.Show("Error while updating record on table..." & ex.Message, "Update Records")
        Finally
          con.Close()
        End Try
      End If
      DailySummaryReview.holidayaddButton.Enabled = False
      Me.Close()
    Next
  End Sub



我希望用户能够单击field4中的复选框,并在单击该字段中的框时将所有数据加上单词Holiday添加到我的数据库,但是现在它不允许我单击复选框,有人可以帮助吗?此外,我确实有这个在该领域工作,但它只允许我添加第一行数据,我的代码中不允许其他行不添加他们的数据?

谢谢


and I want users to be able to click on the checkbox in field4 and add all of the data plus the word Holiday to my database when they click on the box in that field, but right now it's not allowing me to click on the checkbox, can someone please assist? Also, I did have this working for that field but it would only allow me to add the first line of data, what in my code would not allow for the additional lines to not add their data as well?
Thank you

推荐答案

您必须选中DataGridView任务列表中的启用编辑复选框。



查看此处的屏幕截图
You must check the Enable Editing checkbox in the DataGridView Task list.

See the screen shot here


这篇关于无法检查datagridview中的复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆