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
Used a
MaskedTextBoxinstead of a regularTextBox. You can then set theMaskproperty to"N0000", which will only allow the user to enter 4 digits following the'N', and will not let the user edit the'N'. TheTextproperty will give you the displayed text, including the'N'.