Question Multiple Windows Form Questions (Data Entry Form)

ajw1985

New member
Joined
May 25, 2015
Messages
3
Programming Experience
Beginner
Hi All

New user here - have just started using VB most programming experience I have had has been with HTML, CSS and writing if statements in excel.

I have created a Windows Form to ensure an operator is picking an order correctly.

What I want to be able to do is have the end user be able to open the application and if everything is correct save the data to my database.

What I need help with is;
- Getting the form to load in Add New Record Mode so they don't have to click the + sign.
- After they save the data the form should clear / refresh ready for next entry
- I want the datagridview to only show entries from the current date
- I essentially want to get rid of the toolbar as the user doesn't need to be able to scroll through records or delete records

My forms' code is here
VB.NET:
Public Class frmODIS    'This is for displaying the current date and time 
    Dim WithEvents aTimer As New System.Windows.Forms.Timer


    Private Sub frmODIS_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'ODIS_DBDataSet.tblODIS' table. You can move, or remove it, as needed.
        Me.BindingNavigatorAddNewItem.PerformClick()
        Me.TblODISTableAdapter.FillBy(Me.ODIS_DBDataSet.tblODIS)
    End Sub
    Private Sub aTimer_Tick(ByVal sender As Object, _
                            ByVal e As System.EventArgs) Handles aTimer.Tick
        Scan_Date_and_TimeTextBox.Text = DateTime.Now.ToString("MMMM dd, yyyy hh:mm:ss tt")
    End Sub
    'This formats the timing interval
    Private Sub Form1_Shown(ByVal sender As Object, _
                            ByVal e As System.EventArgs) Handles Me.Shown
        aTimer.Interval = 250
        aTimer.Start()
    End Sub
    'Allows Enter To Tab Between Text Boxes
    Private Sub Check_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Operator_NameTextBox.KeyDown, Order_NumberTextBox.KeyDown, Part_NumberTextBox.KeyDown, Part_NumberBoxTextBox.KeyDown, PartCheck.KeyDown, Part_QtyTextBox.KeyDown, Part_Qty_Checked_CheckBox.KeyDown, Scan_Date_and_TimeTextBox.KeyDown
        If e.KeyCode = Keys.Enter Then
            e.Handled = True
            Me.SelectNextControl(sender, True, True, True, True)
        End If
    End Sub
    Private Sub TblODISBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles TblODISBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.TblODISBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.ODIS_DBDataSet)
    End Sub


    'Clears all the text boxes 
    Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
        Dim objControl As Control
        For Each objControl In Me.Controls
            If TypeOf objControl Is TextBox Then
                'Clear the text
                objControl.Text = ""
            End If
        Next
    End Sub
    'Closes the application
    Private Sub btn_Exit_Click(sender As Object, e As EventArgs) Handles btn_Exit.Click
        Application.Exit()
    End Sub
    'Save Button
    Private Sub btn_Save_Click(sender As Object, e As EventArgs) Handles btn_Save.Click
        Me.Validate()
        Me.TblODISBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.ODIS_DBDataSet)
    End Sub
    'Checks that the part numbers match and that the save button is disabled or enabled
    Private Sub PartCheck_TextChanged(sender As Object, e As EventArgs) Handles Part_NumberBoxTextBox.TextChanged, Part_NumberBoxTextBox.TextChanged
        If Part_NumberTextBox.Text = Part_NumberBoxTextBox.Text Then
            PartCheck.Text = "Yes"
            PartCheck.ForeColor = Color.Green
            btn_Save.Enabled = True
        Else
            PartCheck.Text = "No! - Pick Correct Part"
            PartCheck.ForeColor = Color.Red
            btn_Save.Enabled = False
        End If
    End Sub
    'Makes sure that the Qty Text Box is a number
    Private Sub Part_QtyTextBox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Part_QtyTextBox.KeyPress
        If Not Char.IsDigit(e.KeyChar) And Not Char.IsControl(e.KeyChar) Then
            e.Handled = True
        End If
    End Sub


    Private Sub BindingNavigatorAddNewItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorAddNewItem.Click
        Me.Show()
        Me.BindingNavigatorAddNewItem.PerformClick()
    End Sub
End Class

Thanks in advance for your help =)
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,346
Location
Sydney, Australia
Programming Experience
10+
I think I accidentally put this thread in the MS Access Forum can it please be moved to Windows Forms?

Done. For future reference, please use the Report Post icon to send a message directly to all moderators if you need a thread moved or other such moderation.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,346
Location
Sydney, Australia
Programming Experience
10+
That toolbar is a BindingNavigator, which is basically a UI for a BindingSource. If you don't want it, simply delete it in the designer. You can invoke the same members in your own code that it exposes via its buttons. For instance, to create a new row, you simply call the AddNew method of the BindingSource. You can determine which record is exposed via the bound controls by setting the Position or Current property of the BindingSource. You can determine what is displayed in the bound DataGridView by setting the Filter property of the BindingSource.
 
Top Bottom