Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 如何以编程方式设置DataGridView单元格的值?_.net_Vb.net_Datagridview - Fatal编程技术网

.net 如何以编程方式设置DataGridView单元格的值?

.net 如何以编程方式设置DataGridView单元格的值?,.net,vb.net,datagridview,.net,Vb.net,Datagridview,如果符合某些条件,我正在尝试清除手机。但它不起作用 更新 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").

如果符合某些条件,我正在尝试清除手机。但它不起作用

更新

 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
Private子DataGridView1\u CellLeave(ByVal发送方作为System.Object,ByVal e作为System.Windows.Forms.DataGridViewCellEventArgs)处理DataGridView1.CellLeave
Dim laspac As Int16=DataGridView1.Columns(“laspac”).Index
如果e.ColumnIndex=laspac和DataGridView1.Rows(e.RowIndex).Cells(“CType”).Value.ToString.Trim()=B,则
作为DataGridViewCell=DataGridView1.Rows(e.RowIndex.Cells)的Dim B_LASPAC(“LASPAC”)
按DataGridViewCell=DataGridView1.Rows(e.RowIndex-1.Cells(“LASPAC”)对A_LASPAC进行调整
如果B_LASPAC.Value.ToString.Trim.Length为0,则
如果Convert.ToDecimal(B_LASPAC.Value)+Convert.ToDecimal(A_LASPAC.Value)>0,则
B_LASPAC.Value=“”
如果结束
如果结束
如果结束
端接头

非常简单,只需传递行索引和列索引即可

例如

所以,在你的情况下。。。差不多

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

我必须使用
B\u LASPAC.EditedFormattedValue.ToString()
而不是
B\u LASPAC.Value.ToString()
来获取单元格休假时的单元格值,并且我意识到在设置单元格的新值
B\u LASPAC.Value=“”

Private子DataGridView1\u CellLeave(ByVal发送方作为System.Object,ByVal e作为System.Windows.Forms.DataGridViewCellEventArgs)处理DataGridView1.CellLeave
Dim laspac As Int16=DataGridView1.Columns(“laspac”).Index
如果e.ColumnIndex=laspac和DataGridView1.Rows(e.RowIndex).Cells(“CType”).Value.ToString.Trim()=B,则
作为DataGridViewCell=DataGridView1.Rows(e.RowIndex.Cells)的Dim B_LASPAC(“LASPAC”)
按DataGridViewCell=DataGridView1.Rows(e.RowIndex-1.Cells(“LASPAC”)对A_LASPAC进行调整
Dim str As String=DataGridView1.Rows(e.RowIndex).Cells(“LASPAC”).EditedFormattedValue.ToString()
如果B_LASPAC.EditedFormattedValue.ToString.Trim.Length为0,则
如果Convert.ToDecimal(B_LASPAC.EditedFormattedValue.ToString())+Convert.ToDecimal(A_LASPAC.EditedFormattedValue.ToString())>0,则
DataGridView1.EndEdit()
B_LASPAC.Value=“”
如果结束
如果结束
如果结束
端接头

Freud博士承认你的头衔:)什么是“它不起作用?”“你到底是什么意思?你有什么错误吗?它在某些条件下不工作/从不工作等。它不会给我任何错误。。它就是不起作用。从来没有。@thumbmunkeys我不确定这是什么意思,但对我来说似乎是一个好的评论:)好的。您的代码有点复杂,在构建代码时可能包含了一些错误。我们所能做的最大工作就是建立一个清晰的、确保执行您想要的操作的版本(尽管没有正确的输入,它无论如何都不会工作…)。你能清楚地描述一下你试图追踪的行为吗?示例:当列“X”中的单元格为数字且其值为。。。我想触发msgbox。请检查我的更新。。。它起作用了,但只有当我回到牢房离开时它才起作用again@Arbaaz你为什么要处理CellLeave事件?那么我应该使用什么事件?@Arbaaz这取决于你想什么时候更改该单元格的值?最好是在CellLeave上。
If ... Then
    DataGridView1(e.ColumnIndex, e.RowIndex).Value = ""
End If
 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