0

This is my code for setting all the columns to input numbers only:

Private Sub dvBelt_EditingControlShowing(sender As Object, e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles dvBelt.EditingControlShowing
    Try
        RemoveHandler e.Control.KeyPress, AddressOf TextNumberKeypress
        AddHandler e.Control.KeyPress, AddressOf TextNumberKeypress

    Catch ex As Exception
        '... 
    End Try
End Sub

Sub TextNumberKeypress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)

    If Asc(e.KeyChar) >= 33 And Asc(e.KeyChar) <= 47 Or _
        Asc(e.KeyChar) >= 58 Then
        e.Handled = True
    End If

End Sub

Now what I want is to set only the first column to allow inputing numbers only, and the remaining columns can input strings.

Thank you for your help

4

1 に答える 1

1

メソッド内でdvBelt_EditingControlShowing、現在のセルが最初の列を指している場合にのみイベントを登録し、特定のセルに向けて登録します。C++/Cli では、コードは次のようになります

void dvBelt_EditingControlShowing(System::Object ^sender, System::Windows::Forms::DataGridViewEditingControlShowingEventArgs ^e) {
try {

    if (this->dvBelt->CurrentCell->ColumnIndex == 0) { // 0 is the column index for the first column
        //do the removing and adding of your kepress event here
    }
} catch (Exception ^ex) {

}}
于 2013-09-11T04:02:11.687 に答える