Datagridview错误文本 [英] Datagridview Error Text

查看:167
本文介绍了Datagridview错误文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个datagridview,其中有PresentLinkedQty列和PendingToLink列.PendingToLink列是不可编辑的,而PresentLinkedQty列是可编辑的。当用户编辑PresentLinkedQty时,不应该大于PendingToLinkQty。

我是检查PresentLinkedQty中的输入并检查它是否大于cellvalidating事件中的PendingToLink并设置错误text.Error文本如果在设置错误文本后我没有显示我正在设置e.cancel = true。



如果我没有输入e.cancel = true,则会显示错误文本,但在用户选择另一个单元格后,错误文本会消失。



我想要实现的是在验证输入后我会相应地显示错误文本,如果用户输错了,焦点也不应该离开那个单元格。



以下是代码段 -

There is a datagridview where there is PresentLinkedQty column and PendingToLink column.The PendingToLink column is noneditable whereas PresentLinkedQty column is editable.When the user will edit PresentLinkedQty should not be greater than PendingToLinkQty.
I am checking the input in PresentLinkedQty and checking if it is greater than PendingToLink in cellvalidating event and setting the error text.Error text is not getting displayed if after setting the error text i am putting e.cancel=true.

If I am not putting e.cancel=true then error text is displayed but after the user selects another cell the error text goes away.

What i want to achieve is after validating the input i will show the error text accrordingly and also the focus should not leave that cell if the user has put wrong input.

Below is the code snippet-

Private Sub DataGridView1_CellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles DataGridView1.CellValidating
        Dim index As Integer = e.RowIndex
        If e.FormattedValue > CType(DataGridView1.Rows(index).Cells("PendingToLink").Value, Double) Then
            MessageBox.Show("Linked Qty must not be greater than pending to link")
            DataGridView1.CurrentRow.Cells("PresentLinkedQty").ErrorText = "Linked Qty must not be greater than pending to link"
            e.Cancel = True
        Else
            If Not DataGridView1.CurrentRow.Cells("PresentLinkedQty").ErrorText Is Nothing Then
                DataGridView1.CurrentRow.Cells("PresentLinkedQty").ErrorText = String.Empty
            End If
        End If
    End Sub

推荐答案

https://quantboy.wordpress.com/2007/01/03/datagridview-not-showing-errortext/ [ ^ ]







http://codedbot.com/questions/317436/datagridview-not-displaying-the -error-icon-or-error-text [ ^ ]


这篇关于Datagridview错误文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆