【问题标题】:vb.net Unchecked checkbox in datagridview programaticallyvb.net以编程方式未选中datagridview中的复选框
【发布时间】:2017-02-21 23:34:29
【问题描述】:

我这里有一个代码,但它不起作用。我想要做的是当消息框出现并询问我是否要继续并选择否然后选中的复选框将值更改为 false。

If e.ColumnIndex = 0 Then
        If e.RowIndex >= 0 And e.RowIndex <= Me.dgDispatchPosting.RowCount - 1 Then
            If Me.dgDispatchPosting.Item("Approve_Status", e.RowIndex).Value <> "No Action" Then
                If Me.dgDispatchPosting.Item("chkSelect", e.RowIndex).Value = False Then
                    If MsgBox("This Dispatch Code has been " & vbCrLf & "Do you want to proceed? " & Me.dgDispatchPosting.Item("Approve_status", e.RowIndex).Value & "!", vbQuestion + vbYesNo, "Courier Dispatch Summary ") = MsgBoxResult.No Then
                        Me.dgDispatchPosting.Item("chkSelect", e.RowIndex).Value = False 'Must change the value here (Uncheck)
                    End If
                End If
            End If
        End If
    End If

【问题讨论】:

  • 在消息框之前的行中,您检查chkSelect 是否为假。然后显示消息框,如果他们点击否,则再次将其设置为false。我怀疑你想在 MsgBox 之前换行以检查它是否属实?否则代码无事可做。
  • 代码在 _CellContentClick 下,消息框之前的行正在检查是否未选中单击/选中的复选框..如果尚未选中选中的复选框,则会弹出消息框,但如果复选框是已经检查了消息框会弹出..然后当我点击 NO 时,单击/选中的复选框将变为 false。
  • 您最后的评论没有意义。您说“如果尚未选中选定的复选框,则将弹出消息框”然后您说“如果已选中该复选框,则会弹出消息框”根据您的代码,弹出消息框的唯一方法是值chkSelect 是假的。然后你直接把它设置回 false,这是它的当前值。
  • 您可能还会遇到事件计时问题。与触发单元格单击事件的时间相比,我不确定复选框列的值何时更新。尝试将其移至CellValueChanged
  • 抱歉,如果单击的复选框为假,则会弹出消息框。我想要的是当消息框弹出并且我点击否时。选中的复选框将变为假。跨度>

标签: vb.net


【解决方案1】:

我已经知道如何取消选中datagridview 中的复选框。我只是在更改复选框值后选择/关注另一列/行。

If Me.dgDispatchPosting.Item("chkSelect", e.RowIndex).Value = True Then
   If MsgBox("This Dispatch Code has been " & Me.dgDispatchPosting.Item("Approve_status", e.RowIndex).Value & "!" & vbCrLf & "Do you want to proceed? ", vbQuestion + vbYesNo, "Courier Dispatch Summary ") = MsgBoxResult.No Then
      'Must change the value here (Uncheck)'Must change the value here(Uncheck)
      Me.dgDispatchPosting.Item("chkSelect", e.RowIndex).Value = False 
      'After Changing the value you must select/ focus in the other column or row to take effect the changes you made in code.
      Me.dgDispatchPosting.Item("Approve_status", e.RowIndex).Selected = True 
   End If
End If

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-06
    • 2016-11-05
    • 2021-11-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多