2014-01-07 3 views
0

특정 조건이 충족되면 셀을 지우려고합니다. 그러나 그것은 작동하지 않습니다.DataGridView 셀의 값을 프로그래밍 방식으로 설정하는 방법은 무엇입니까?

UPDATE는

Private Sub DataGridView1_CellLeave(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellLeave 
     Dim laspac As Int16 = DataGridView1.Columns("LASPAC").Index 

     If e.ColumnIndex = laspac And DataGridView1.Rows(e.RowIndex).Cells("CType").Value.ToString.Trim() = "B" Then 
      Dim B_LASPAC As DataGridViewCell = DataGridView1.Rows(e.RowIndex).Cells("LASPAC") 
      Dim A_LASPAC As DataGridViewCell = DataGridView1.Rows(e.RowIndex - 1).Cells("LASPAC") 
      If B_LASPAC.Value.ToString.Trim.Length <> 0 Then 

       If Convert.ToDecimal(B_LASPAC.Value) + Convert.ToDecimal(A_LASPAC.Value) > 0 Then 

        B_LASPAC.Value = "" 


       End If 
      End If 


     End If 
    End Sub 
+2

박사 프로이트는 제목을 인정 :) – thumbmunkeys

+0

"그것이 작동하지 않는다"는 것이 정확히 무엇을 의미합니까? 어떤 오류가 있습니까? 특정 조건/절대로 작동하지 않습니까? 등 – varocarbas

+0

그것은 어떤 오류도주지 않습니다 .. 단지 작동하지 않습니다. 못. – Arbaaz

답변

1

그것은 아주 쉽게, 그냥 rowIndex에columnIndex에

예를 전달합니다.

Dim rowId = 0 
Dim colId = 1 

DataGridView1(colId, rowId).Value = "HELLO" 

그래서

If ... Then 
    DataGridView1(e.ColumnIndex, e.RowIndex).Value = "" 
End If 
+0

내 업데이트를 확인하십시오 ... 작동하지만 셀로 돌아가서 다시 나가야 만 작동합니다. – Arbaaz

+0

@Arbaaz 왜 CellLeave 이벤트를 처리하고 있습니까? – Vland

+0

그럼 어떤 이벤트를 사용해야합니까? – Arbaaz

0

같은, 귀하의 경우 ... 뭔가 내가 휴대 휴가에있는 셀의 값을 얻기 위해 B_LASPAC.EditedFormattedValue.ToString() 대신 B_LASPAC.Value.ToString()을 사용했고 또한 내가 필요 실현 나는 셀의 새로운 값을 설정하기 직전 DataGridView1.EndEdit()를 사용하여 DataGridView에의 한 EditMode을 종료 B_LASPAC.Value = ""

Private Sub DataGridView1_CellLeave(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellLeave 
     Dim laspac As Int16 = DataGridView1.Columns("LASPAC").Index 

     If e.ColumnIndex = laspac And DataGridView1.Rows(e.RowIndex).Cells("CType").Value.ToString.Trim() = "B" Then 
      Dim B_LASPAC As DataGridViewCell = DataGridView1.Rows(e.RowIndex).Cells("LASPAC") 
      Dim A_LASPAC As DataGridViewCell = DataGridView1.Rows(e.RowIndex - 1).Cells("LASPAC") 
      Dim str As String = DataGridView1.Rows(e.RowIndex).Cells("LASPAC").EditedFormattedValue.ToString() 
      If B_LASPAC.EditedFormattedValue.ToString.Trim.Length <> 0 Then 
       If Convert.ToDecimal(B_LASPAC.EditedFormattedValue.ToString()) + Convert.ToDecimal(A_LASPAC.EditedFormattedValue.ToString()) > 0 Then 

        DataGridView1.EndEdit() 
        B_LASPAC.Value = "" 

       End If 
      End If 
     End If 
    End Sub 
관련 문제