如何以编程方式设置DataGridView单元的值? [英] How to set value of a DataGridView Cell programatically?
本文介绍了如何以编程方式设置DataGridView单元的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果满足某些条件,我将尝试清除单元格。但是它不起作用。
I am trying to clear the cell if certain conditions are met. But its not working.
更新
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
推荐答案
非常简单,通过 RowIndex 和 ColumnIndex
例如。
Dim rowId = 0
Dim colId = 1
DataGridView1(colId, rowId).Value = "HELLO"
所以,在您的情况下...类似
so, in your case... something like
If ... Then
DataGridView1(e.ColumnIndex, e.RowIndex).Value = ""
End If
这篇关于如何以编程方式设置DataGridView单元的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文