Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.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
String 数据无效时清除UltraGridCell中的文本_String_Vb.net_Decimal_Infragistics_Ultrawingrid - Fatal编程技术网

String 数据无效时清除UltraGridCell中的文本

String 数据无效时清除UltraGridCell中的文本,string,vb.net,decimal,infragistics,ultrawingrid,String,Vb.net,Decimal,Infragistics,Ultrawingrid,我试图在UltraGrid中添加一些验证,如果用户在一个单元格中键入一个值,但没有将CheckBoxColumn的值设置为True,则会显示一个MessageBox,并清除该单元格中的文本/值,再次留下一个空白单元格 到目前为止,我得到的是: Try If e.Cell.Column.Key = "Commission_Rate" Then If e.Cell.Row.Cells("Commission_Override").Value = False Then

我试图在UltraGrid中添加一些验证,如果用户在一个单元格中键入一个值,但没有将CheckBoxColumn的值设置为True,则会显示一个MessageBox,并清除该单元格中的文本/值,再次留下一个空白单元格

到目前为止,我得到的是:

Try
    If e.Cell.Column.Key = "Commission_Rate" Then
        If e.Cell.Row.Cells("Commission_Override").Value = False Then
           MessageBox.Show("Before entering a custom rate, please set 'Commission Override' to True", "Override Commission", MessageBoxButtons.OK)
            e.Cell.Value = ""
        End If
    End If
Catch
End Try
MessageBox行工作正常,但是,另一行显示为

无法从:System.String转换为System.Decimal


该单元格是十进制单元格,因为它用于输入货币值,因此如何将该值设置为十进制?

当没有提供值时,从数据库中获取的值为DBNull.value。因此,如果需要单元格不显示任何内容,则需要如下设置相同的值:

e.Cell.Value = DBNull.Value
这将强制网格显示空单元格

[编辑] 在BeforeEnteredMode事件中使用此代码,在未选中相关复选框单元格时禁止用户编辑单元格:

    Private Sub UltraGrid1_BeforeEnterEditMode(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles UltraGrid1.BeforeEnterEditMode
    Dim cell As UltraGridCell = Me.UltraGrid1.ActiveCell
    If cell Is Nothing Then
        Return
    End If
    Try
        If cell.Column.Key = "Commission_Rate" Then
            If cell.Row.Cells("Commission_Override").Value = False Then
                MessageBox.Show("Before entering a custom rate, please set 'Commission Override' to True", "Override Commission", MessageBoxButtons.OK)
                e.Cancel = True
            End If
        End If
    Catch
    End Try
End Sub

这类栏目通常是打字的;在这种情况下,它映射到的db列需要一个数字十进制,因此需要0或类似的值。此外,DGV无论如何都提供了RowValidation,但不清楚它在哪里is@Plutonix加载网格时,它不显示任何内容,是否有办法删除键入的字符?e.Cell.Value=Nothing@Steve这没有返回第二个MessageBox,但也没有重置值。这几乎可以正常工作。。。它返回消息框,按“OK”后,输入的值保留在单元格中,直到我编辑网格中的另一个单元格。不确定这是什么意思。如果将单元格的值设置为DBNull.value,则单元格中不会显示所需的任何内容。但是,我也不确定在哪种情况下调用所有这些代码。如果您分享一些关于您的上下文的更多信息,我们可能会尝试给您一个解决方案:嗨,我在CellChange事件中有这个代码,这可能就是问题所在?它需要在BeforeRowUpdate/AfterRowUpdate中吗?好的,在我看来,最好的地方是在beforeEnteredMode事件中。在这种情况下,您可以选中该复选框,如果未选中相关复选框,则不允许单元格进入编辑模式。我在我的答案中添加了一个代码片段,这应该会很完美,谢谢!如果需要,我可以修改它,但这是我需要的基本功能