Reputation: 24
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.
Please help guys. Thanks
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
Upvotes: 0
Views: 278
Reputation: 57803
Used a MaskedTextBox
instead of a regular TextBox
. You can then set the Mask
property to "N0000"
, which will only allow the user to enter 4 digits following the 'N'
, and will not let the user edit the 'N'
. The Text
property will give you the displayed text, including the 'N'
.
Upvotes: 1
Reputation: 1399
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.
That way you should be able to fix it.
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.
This would be your regex then.
^(N?[0-9]{4})$
Hope this can be of any use to you
Upvotes: 1