English 中文(简体)
数据组编辑问题
原标题:DataGridView Cell Editing issue with decimal/hexadecimal formatting

我有一份<>DataGridView 约束至DataTable,其中1+16栏被定义为Integer

缺电电池体为六dec二位数(.Format=“X2”)。

在进入编辑室时,我谨向用户提供在德西马尔或黑塞哥勒书写价值的可能性。

  1. Hexadecimal could be written like, for example, 0x00, 0X01, x02, XFF
  2. Decimal like 0, 1, 2, 15

为此原因,请见。 纽约总部 我在文本Box值中添加“0x”

Private Sub BankGrid_EditingControlShowing(ByVal sender As Object, ByVal e As DataGridViewEditingControlShowingEventArgs)

    Dim grid As DataGridView = DirectCast(sender, DataGridView)
    If Not TypeOf e.Control Is TextBox Then Return

    Dim tb As TextBox = DirectCast(e.Control, TextBox)
    tb.Text = "0x" & tb.Text

    RemoveHandler tb.KeyPress, AddressOf TextBox_KeyPress
    AddHandler tb.KeyPress, AddressOf TextBox_KeyPress

End Sub

TextBox_KeyPress下,I进行所有输入过滤,以避免产生无效的投入。

我无法理解的是,在完成编辑工作时,我可以附上哪些活动。 我想谈谈EditingControlShowing,以便我能够删除“0x”但我发现它。

最佳回答

在尝试了文本Box和数据GRidView中可能发生的所有事件之后,我最后认为对我的案件有用。

<><>

我照抄我的法典,或许可以帮助其他人:

   Private Sub BankGrid_CellParsing(ByVal sender As Object, ByVal e As DataGridViewCellParsingEventArgs)

        Dim grid As DataGridView = DirectCast(sender, DataGridView)
        Dim cell As CustomCell = DirectCast(grid(e.ColumnIndex, e.RowIndex), CustomCell)

        If e.Value Is Nothing OrElse String.IsNullOrEmpty(e.Value.ToString) Then
            e.Value = cell.Value
        Else

            Dim iValue As Integer
            If TryParseNumeric(e.Value.ToString, iValue) Then

                If iValue >= 0 AndAlso iValue <= &HFF Then
                    e.Value = iValue   value inside the range, accept it 
                Else
                    e.Value = cell.Value  value outside the range, reload old value 
                End If

            Else                    
                e.Value = cell.Value  invalid input, reload old value 
            End If

        End If

        e.ParsingApplied = True

    End Sub
问题回答

我将使用电网电文处理器。 如果时间太晚,则使用手机





相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?