English 中文(简体)
如何插入“N”字,然后是4位数。 4位数由用户输入方框
原标题:How to insert letter "N" and have followed by 4 digits. The 4 digits is entered by the user in to the text box

NOTE: I tried using concat() method, join method and even tried to insert just text(which turned out editable) but none of them worked as I wanted. I was thinking if substring method will work but I only have basic idea of how substring works. I want the letter "N" to be inserted into the text box when form loads and when the user enters 4digits(OrderNo2.text) which should be joined so that it can be saved together when I clicked on save button.

请帮助。 增 编

Private Sub btnAddOrder_Click(ByVal sender As System.Object, ByVal e
  As System.EventArgs) Handles btnAddOrder.Click



isNewRow = True
        Dim newRow As DataRow = dsOrders.Tables("Orders").NewRow

        Try
            If txtOrderNo2.Text.Length = 5 Then
                newRow.Item("OrderNo") = txtOrderNo2.Text
                If cbo_Product.SelectedIndex <> -1 Then
                    newRow.Item("Product") = cbo_Product.Text
                    newRow.Item("Price") = txtPrice2.Text
                    If txtQuantity.Text <> "" Then
                        newRow.Item("Quantity") = txtQuantity.Text
                        newRow.Item("CustomerNo") = txtCustomerNo2.Text
                        dsOrders.Tables("Orders").Rows.Add(newRow)
                         determine row index of new row
                        rowIndex = dsOrders.Tables("Orders").Rows.Count - 1
                         save changes back to the database
                        daOrders.Update(dsOrders, "Orders")

                    Else
                        MessageBox.Show("Please enter the quantity", "Missing Quantity", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    End If
                Else
                    MessageBox.Show("Please choose the product", "Missing Price", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                End If
            Else
                MessageBox.Show("Order Number must be 5 digits long!", "Missing Order Number", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub
最佳回答

Used a code>MaskedTextBox,而不是常规的TextBox。 之后,你可以确定Mask property to N0000",这只会使用户在后进入4位数。 纽约总部 大会和会议管理部印发 N 。 www.un.org/chinese/sc/presidency.asp N 。

问题回答

Try just allowing only digits in the textbox with a max lenght of 4. Then if the user clicks on the submit button just get the value of the input and place the N infront of it. You will always have a length of 4 + your character("N") is 5.

这样,你就能够确定。

You can also try using a regex. to see if it contains the N and numbers from 0-9. only if it starts with the character N followed by 4 numberic characters it will be a valid input.

届时你会这样做。

^(N?[0-9]{4})$

希望能对你们有任何用处。





相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

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 ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.

热门标签