2016-09-17 7 views
-1

후 값을 되돌립니다.DataGridView에 체크 박스가 나는 프로그램을 가지고 있으며이</p> <p><a href="https://i.stack.imgur.com/C6FRt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/C6FRt.png" alt="enter image description here"></a></p> <p>값을 확인하고 색상 빨간색과 하나를 집중하시기 바랍니다과 같은 사용자 확인

내가 셀을 클릭하면 내가 Yes을 클릭 프로그램이 현재 값을 확인하고 그것을 뭔가를 업데이트 할 경우 MSGBOX 먼저 sayon ​​Are you you want to update changes?

표시됩니다 셀 (checkboxcolumn)

을 클릭합니다 말할 수 있습니다 이.

If value = yes then 
value = No 
elseif value = no then 
value = Yes 
end if 

와 나는 MSGBOX에 NO을 선택하면 현재 셀의 의지의 값은 동일하게 유지됩니다.

여기 내 코드 내 질문은

If (e.ColumnIndex = 1 AndAlso e.RowIndex >= 0) Then 
      Dim value = DirectCast(DataGridView1(e.ColumnIndex, e.RowIndex).FormattedValue, Nullable(Of Boolean)) 
      Dim result = MessageBox.Show("Are you sure to uncheck item?", "", MessageBoxButtons.YesNoCancel) 
      If (value.HasValue AndAlso value = True) Then 

       If (result = System.Windows.Forms.DialogResult.Yes) Then 

        If DataGridView1(e.ColumnIndex, e.RowIndex).Value = True Then 
         DataGridView1(e.ColumnIndex, e.RowIndex).Value = False 
        Else 
         DataGridView1(e.ColumnIndex, e.RowIndex).Value = True 
        End If 
       ElseIf (result = System.Windows.Forms.DialogResult.No) Then 

       End If 
      Else 

      End If 
     End If 

입니다.

messagebox에서 Yes를 클릭하면 어떻게 셀의 값을 확인하고 반대로 바꿀 수 있습니까? 메시지 상자에서 NO를 클릭하면 값이 그대로 유지되거나 원래 값으로 돌아갑니다.

나는 위의 내 코드를 시도하지만 작동하지 보이는

TYSM 당신은 같은 기준을 사용할 수 있습니다

+0

확인 여부를 확인하기 전에 언 체킹을 원하는지 묻습니다. 사용자를 싫어해야합니다. – Plutonix

+0

진심으로 선생님, 나는 그들을 정말로 싫어합니다. 제발 저를 도와주세요. –

+0

* what *? 당신은 질문을하지 않았고 게시물의 텍스트가 코드와 일치하지 않습니다. – Plutonix

답변

1

: 나는 사용자와 경우에 확인 메시지를 보여 위의 코드에서

Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, _ 
    ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick 
    If (e.ColumnIndex = 0 AndAlso e.RowIndex >= 0) Then 
     Dim value = DirectCast(DataGridView1(e.ColumnIndex, e.RowIndex).FormattedValue, _ 
           Nullable(Of Boolean)) 
     Dim result = MessageBox.Show("Are you sure to change vaule?", "", _ 
            MessageBoxButtons.YesNoCancel) 
     If (result = System.Windows.Forms.DialogResult.Yes) Then 
      If (value.HasValue AndAlso value = True) Then 
       DataGridView1(e.ColumnIndex, e.RowIndex).Value = False 
      Else 
       DataGridView1(e.ColumnIndex, e.RowIndex).Value = True 
      End If 
     End If 
    End If 
End Sub 

을 사용자가 Yes을 선택하면 셀 값이 되돌려졌습니다.

위 코드에서 나는 첫 번째 열에 대한 확인을 표시하기 위해 e.ColumnIndex = 0을 사용했습니다. 다른 기준 (예 : e.ColumnIndex = 1)이 필요할 수 있습니다. 다른 예로는 (e.ColumnIndex >=1 AndAlso e.ColumnIndex <=13)입니다.

e.RowIndex >= 0 이벤트가 데이터 셀과 헤더 셀에 대해 처리되는지 확인합니다.