How to make changes on one form that will change information on another form-VBForums
Results 1 to 15 of 15

Thread: How to make changes on one form that will change information on another form

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2017
    Posts
    40

    How to make changes on one form that will change information on another form

    I am trying to get column 6 in the data grid view to be subtracted by 1 when the save button is pressed. The problem is the data grid view of column 6 is on my book_table form and the save button that i will press to subtract 1 from the data grid view is on my transaction form.

    I have written this bit of code but it does not seem to work. i created a variable called butclcik and set its return type as a boolean. (Public butclcik As Boolean) Then i made an instance of the Book table called boktble. (Dim boktble As Book_Table = New Book_Table) I then tried to subtract 1 from the datagridview column 6 like this

    Double.Parse((boktble.Book_TableDataGridView.Columns(6).ValueType = boktble.Book_TableDataGridView.Columns(6).ValueType) - 1)


    vb.net Code:
    1. Dim boktble As Book_Table = New Book_Table
    2.     Public butclcik As Boolean
    3.     Private Sub SaveButton_Click(sender As Object, e As EventArgs) Handles SaveButton.Click
    4.         butclcik = True
    5.         Try
    6.             If butclcik = True Then
    7.                 Double.Parse((boktble.Book_TableDataGridView.Columns(6).ValueType = boktble.Book_TableDataGridView.Columns(6).ValueType) - 1)
    8.             End If
    9.  
    10.             Dim datatiercal As DataTier = New DataTier(Due_DateDateTimePicker.Value.Date, Return_DateDateTimePicker.Value.Date)
    11.             CostTextBox.Text = String.Format("{0:c2}", datatiercal.finepreiceprocal)
    12.             DayOverduetextbox.Text = datatiercal.Daysoverdueprocal
    13.             Transaction_TableDataGridView.Columns(7).DefaultCellStyle.Format = "c"
    14.             Me.Validate()
    15.             Me.Transaction_TableBindingSource.EndEdit()
    16.             Me.TableAdapterManager.UpdateAll(Me.LibrarymanagementDataSet2)
    17.             CostTextBox.Text = String.Format("{0:c2}", datatiercal.finepreiceprocal)
    18.             MsgBox("Transaction was saved")
    19.         Catch ex As Exception
    20.             MessageBox.Show(ex.Message)
    21.         End Try
    22.     End Sub

    This is all the code in my transaction form.

    vb.net Code:
    1. Public Class Transactions_Table
    2.     Private Shared Instance As Transactions_Table
    3.     Public Shared ReadOnly Property TransactionsTableInstance() As Transactions_Table
    4.         Get
    5.             If Instance Is Nothing Then
    6.                 Instance = New Transactions_Table
    7.             End If
    8.             Return Instance
    9.         End Get
    10.     End Property
    11.     Private Sub Transaction_TableBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs)
    12.         Me.Validate()
    13.         Me.Transaction_TableBindingSource.EndEdit()
    14.         Me.TableAdapterManager.UpdateAll(Me.LibrarymanagementDataSet2)
    15.  
    16.     End Sub
    17.  
    18.     Private Sub Transactions_Table_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    19.         Me.Book_TableTableAdapter1.Fill(Me.LibrarymanagementDataSet2.Book_Table)
    20.         'TODO: This line of code loads data into the 'LibrarymanagementDataSet2.Transaction_Table' table. You can move, or remove it, as needed.
    21.         Me.Transaction_TableTableAdapter.Fill(Me.LibrarymanagementDataSet2.Transaction_Table)
    22.     End Sub
    23.  
    24.  
    25.     Dim boktble As Book_Table = New Book_Table
    26.     Public butclcik As Boolean
    27.     Private Sub SaveButton_Click(sender As Object, e As EventArgs) Handles SaveButton.Click
    28.         butclcik = True
    29.         Try
    30.             If butclcik = True Then
    31.                 Double.Parse((boktble.Book_TableDataGridView.Columns(6).ValueType = boktble.Book_TableDataGridView.Columns(6).ValueType) - 1)
    32.             End If
    33.  
    34.             Dim datatiercal As DataTier = New DataTier(Due_DateDateTimePicker.Value.Date, Return_DateDateTimePicker.Value.Date)
    35.             CostTextBox.Text = String.Format("{0:c2}", datatiercal.finepreiceprocal)
    36.             DayOverduetextbox.Text = datatiercal.Daysoverdueprocal
    37.             Transaction_TableDataGridView.Columns(7).DefaultCellStyle.Format = "c"
    38.             Me.Validate()
    39.             Me.Transaction_TableBindingSource.EndEdit()
    40.             Me.TableAdapterManager.UpdateAll(Me.LibrarymanagementDataSet2)
    41.             CostTextBox.Text = String.Format("{0:c2}", datatiercal.finepreiceprocal)
    42.             MsgBox("Transaction was saved")
    43.         Catch ex As Exception
    44.             MessageBox.Show(ex.Message)
    45.         End Try
    46.     End Sub
    47.  
    48.     Private Sub Transactions_Table_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
    49.         Instance = Nothing
    50.     End Sub
    51.  
    52.     Private Sub Transaction_TableBindingNavigatorSaveItem_Click_1(sender As Object, e As EventArgs) Handles Transaction_TableBindingNavigatorSaveItem.Click
    53.         Me.Validate()
    54.         Me.Transaction_TableBindingSource.EndEdit()
    55.         Me.TableAdapterManager.UpdateAll(Me.LibrarymanagementDataSet2)
    56.  
    57.     End Sub
    58.  
    59.     Private Sub AddButton_Click(sender As Object, e As EventArgs) Handles AddButton.Click
    60.         Try
    61.             Dim datatiercal As DataTier = New DataTier(Due_DateDateTimePicker.Value.Date, Return_DateDateTimePicker.Value.Date)
    62.             CostTextBox.Text = String.Format("{0:c2}", datatiercal.finepreiceprocal)
    63.             Transaction_TableBindingSource.AddNew()
    64.             DayOverduetextbox.Text = datatiercal.Daysoverdueprocal
    65.             CostTextBox.Text = String.Format("{0:c2}", datatiercal.finepreiceprocal)
    66.         Catch ex As Exception
    67.             MessageBox.Show(ex.Message)
    68.         End Try
    69.     End Sub
    70.  
    71.     Private Sub DeleteButton_Click(sender As Object, e As EventArgs) Handles DeleteButton.Click
    72.         Try
    73.             Dim result As Integer = MessageBox.Show("Are you sure you want to delete this Transaction", "Delete Transaction", MessageBoxButtons.YesNo)
    74.             If result = DialogResult.No Then
    75.                 MessageBox.Show("Transaction was not deleted")
    76.             ElseIf result = DialogResult.Yes Then
    77.                 Transaction_TableBindingSource.RemoveCurrent()
    78.                 MessageBox.Show("The Transaction was deleted")
    79.             End If
    80.  
    81.         Catch ex As Exception
    82.             MessageBox.Show(ex.Message)
    83.         End Try
    84.     End Sub
    85.  
    86.     Private Sub UpdateButton_Click(sender As Object, e As EventArgs) Handles UpdateButton.Click
    87.         Try
    88.             Dim datatiercal As DataTier = New DataTier(Due_DateDateTimePicker.Value.Date, Return_DateDateTimePicker.Value.Date)
    89.             CostTextBox.Text = String.Format("{0:c2}", datatiercal.finepreiceprocal)
    90.             DayOverduetextbox.Text = datatiercal.Daysoverdueprocal
    91.             Transaction_TableDataGridView.Columns(7).DefaultCellStyle.Format = "c"
    92.             Me.Validate()
    93.             Me.Transaction_TableBindingSource.EndEdit()
    94.             Me.TableAdapterManager.UpdateAll(Me.LibrarymanagementDataSet2)
    95.             CostTextBox.Text = String.Format("{0:c2}", datatiercal.finepreiceprocal)
    96.             MsgBox("Transaction was Updated")
    97.         Catch ex As Exception
    98.             MessageBox.Show(ex.Message)
    99.         End Try
    100.     End Sub
    101.  
    102.     Private Sub RenewButton_Click(sender As Object, e As EventArgs) Handles RenewButton.Click
    103.         Try
    104.             Due_DateDateTimePicker.Value = Due_DateDateTimePicker.Value.Date.AddDays(7)
    105.             Return_DateDateTimePicker.Value = Due_DateDateTimePicker.Value.Date
    106.             Dim datatiercal As DataTier = New DataTier(Due_DateDateTimePicker.Value.Date, Return_DateDateTimePicker.Value.Date)
    107.             CostTextBox.Text = String.Format("{0:c2}", datatiercal.finepreiceprocal)
    108.             DayOverduetextbox.Text = datatiercal.Daysoverdueprocal
    109.             Transaction_TableDataGridView.Columns(7).DefaultCellStyle.Format = "c"
    110.             Me.Validate()
    111.             Me.Transaction_TableBindingSource.EndEdit()
    112.             Me.TableAdapterManager.UpdateAll(Me.LibrarymanagementDataSet2)
    113.             CostTextBox.Text = String.Format("{0:c2}", datatiercal.finepreiceprocal)
    114.             MsgBox("The Book has Been Renews for a week")
    115.         Catch ex As Exception
    116.             MessageBox.Show(ex.Message)
    117.         End Try
    118.     End Sub
    119.  
    120.     Private Sub FillByToolStripButton_Click(sender As Object, e As EventArgs)
    121.         Try
    122.             Me.Transaction_TableTableAdapter.FillBy(Me.LibrarymanagementDataSet2.Transaction_Table)
    123.         Catch ex As System.Exception
    124.             System.Windows.Forms.MessageBox.Show(ex.Message)
    125.         End Try
    126.  
    127.     End Sub
    128.  
    129.     Private Sub IDToolStripButton_Click(sender As Object, e As EventArgs) Handles IDToolStripButton.Click
    130.         Try
    131.             Me.Transaction_TableTableAdapter.ID(Me.LibrarymanagementDataSet2.Transaction_Table, CType(Param1ToolStripTextBox.Text, Integer))
    132.         Catch ex As System.Exception
    133.             System.Windows.Forms.MessageBox.Show(ex.Message)
    134.         End Try
    135.  
    136.     End Sub
    137.  
    138.  
    139.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    140.         Try
    141.             Transaction_TableBindingSource.MovePrevious()
    142.         Catch ex As Exception
    143.             MsgBox(ex.Message)
    144.         End Try
    145.     End Sub
    146.  
    147.     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    148.         Try
    149.             Transaction_TableBindingSource.MoveNext()
    150.         Catch ex As Exception
    151.             MsgBox(ex.Message)
    152.         End Try
    153.     End Sub
    154. End Class
    Last edited by Srut; Dec 15th, 2017 at 06:53 PM.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    98,281

    Re: How to make changes on one form that will change information on another form

    Which forum creates and displays the other and how does it do it? I'm on a phone and there appears to be a lot of irrelevant code to look through to see whether you've included that.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2017
    Posts
    40

    Re: How to make changes on one form that will change information on another form

    I have a form called book management system which is a mdi container. from the book management form i can open the transaction _form and book_form. what i want to do is have the transaction form subtract a value from the data grid form on the Book_form. but the code i wrote to do this isn't working and i am unsure why.

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 2017
    Posts
    40

    Re: How to make changes on one form that will change information on another form

    Anyone else who reads this have any idea could use all the help i get

  5. #5
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    3,588

    Re: How to make changes on one form that will change information on another form

    This line has problems,
    Code:
    Double.Parse((boktble.Book_TableDataGridView.Columns(6).ValueType = boktble.Book_TableDataGridView.Columns(6).ValueType) - 1)
    Your trying to subtract 1 from a dgv column ValueType, do you really want to change the columns value type?

    It sounds like you want to change a value in the Books table after you have changed a value in the transaction table. If so, then work directly with the books table. then when you open the Books_Table form the value will already be correct.

  6. #6

    Thread Starter
    Member
    Join Date
    Nov 2017
    Posts
    40

    Re: How to make changes on one form that will change information on another form

    i tired working with the book table directly but the butclick variable stay false when i check if the button was pressed. can you give me more detail about how to get it to work directly from the book_table

  7. #7
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    3,588

    Re: How to make changes on one form that will change information on another form

    Quote Originally Posted by Srut View Post
    i tired working with the book table directly but the butclick variable stay false when i check if the button was pressed. can you give me more detail about how to get it to work directly from the book_table
    It's hard for me to even respond to this because it really doesn't make sense. At least not to me.
    this code,
    Code:
        Public butclcik As Boolean
        Private Sub SaveButton_Click(sender As Object, e As EventArgs) Handles SaveButton.Click
            butclcik = True
            Try
                If butclcik = True Then
                    Double.Parse((boktble.Book_TableDataGridView.Columns(6).ValueType = boktble.Book_TableDataGridView.Columns(6).ValueType) - 1)
                End If
    Doesn't make sense. butclcik is ALWAYS true when you click the Savebutton, it really doesn't serve any purpose.

    I can't really help with working directly with the Book table without more information.
    I am trying to get column 6 in the data grid view to be subtracted by 1 when the save button is pressed
    I'm guessing that the dgv column 6 is bound to a field in the Book table. Are you saying you want to subtract 1 from the value in that field for EVERY row in that table? If so you can do that by manually cycling through the Me.LibrarymanagementDataSet2.Book_Table datatable using a For/Next loop or add an Update Query to the Book_TableTableAdapter in the LibrarymanagementDataSet2 dataset.

  8. #8
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    5,622

    Re: How to make changes on one form that will change information on another form

    If you have an object on a Form, and you want to access that object from another Form, you must declare that object variable as a public variable, or use a public property to access the object if it's variable is private. It's no different to manipulating objects on any other class.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena


    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. -jmcilhinney

  9. #9
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    98,281

    Re: How to make changes on one form that will change information on another form

    If you want one MDI child form to affect a change on another then the "proper" way is to do it without either knowing that the other exists. If child A is to make a change on child B then child A should raise an event, the parent form should handle that event and call a method of child B and then child B should make the change.

    I'm guessing that you don't want to go that far though, so the options for child A getting direct access to child B are:

    1. If child B is the default instance of it's type then child A can access it via the default instance.
    2. Child A can use a loop or LINQ query to get a reference to child B from the MdiChildren collection of its MdiParent.
    3. The parent form can pass a child B reference into child A.

    You need to decide which way you want to go.

    Once child A has a reference to child B, I would still very much suggest that child A simply calls a method and the actual change is made by child B to itself within that method.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10

    Thread Starter
    Member
    Join Date
    Nov 2017
    Posts
    40

    Re: How to make changes on one form that will change information on another form

    Quote Originally Posted by wes4dbt View Post
    It's hard for me to even respond to this because it really doesn't make sense. At least not to me.
    this code,
    Code:
        Public butclcik As Boolean
        Private Sub SaveButton_Click(sender As Object, e As EventArgs) Handles SaveButton.Click
            butclcik = True
            Try
                If butclcik = True Then
                    Double.Parse((boktble.Book_TableDataGridView.Columns(6).ValueType = boktble.Book_TableDataGridView.Columns(6).ValueType) - 1)
                End If
    Doesn't make sense. butclcik is ALWAYS true when you click the Savebutton, it really doesn't serve any purpose.

    I can't really help with working directly with the Book table without more information.

    I'm guessing that the dgv column 6 is bound to a field in the Book table. Are you saying you want to subtract 1 from the value in that field for EVERY row in that table? If so you can do that by manually cycling through the Me.LibrarymanagementDataSet2.Book_Table datatable using a For/Next loop or add an Update Query to the Book_TableTableAdapter in the LibrarymanagementDataSet2 dataset.
    ok so i made a method in the book table called Copiescount()
    vb.net Code:
    1. Public Sub Copiescount()
    2.         If Transactions_Table.butclcik = True Then
    3.             CopiesTextBox.Text = Double.Parse((CopiesTextBox.Text = CopiesTextBox.Text) - 1)
    4.             Me.TableAdapterManager.UpdateAll(Me.LibrarymanagementDataSet2)
    5.             Me.Book_TableTableAdapter.Update(Me.LibrarymanagementDataSet2)
    6.         End If
    7.     End Sub

    here i check to see if the butclcik is true in the transaction form before doing the calculations in the book form. when i check if the butclcik value is true it comes back correct so that part is fine. the problem is the calculation is not being made. p.s in changed it to the copiestextbox instead of the datagridview.
    Last edited by Srut; Dec 17th, 2017 at 11:15 AM.

  11. #11

    Thread Starter
    Member
    Join Date
    Nov 2017
    Posts
    40

    Re: How to make changes on one form that will change information on another form

    Quote Originally Posted by Niya View Post
    If you have an object on a Form, and you want to access that object from another Form, you must declare that object variable as a public variable, or use a public property to access the object if it's variable is private. It's no different to manipulating objects on any other class.
    i did do this in the transaction table to get the value of butclcik in the Book_table and it works now thank you but the problem is getting the expression to make the subtraction from the values in the book_table after it checks if butclcik is true in the Transaction table.

    vb.net Code:
    1. Public Shared butclcik As Boolean
    2.     Private Sub SaveButton_Click(sender As Object, e As EventArgs) Handles SaveButton.Click
    3.         Try
    4.             butclcik = True
    5.  
    6.  
    7.             Dim datatiercal As DataTier = New DataTier(Due_DateDateTimePicker.Value.Date, Return_DateDateTimePicker.Value.Date)
    8.             CostTextBox.Text = String.Format("{0:c2}", datatiercal.finepreiceprocal)
    9.             DayOverduetextbox.Text = datatiercal.Daysoverdueprocal
    10.             Transaction_TableDataGridView.Columns(7).DefaultCellStyle.Format = "c"
    11.             Me.Validate()
    12.             Me.Transaction_TableBindingSource.EndEdit()
    13.             Me.Book_TableTableAdapter1.Update(Me.LibrarymanagementDataSet2)
    14.             Me.TableAdapterManager.UpdateAll(Me.LibrarymanagementDataSet2)
    15.             CostTextBox.Text = String.Format("{0:c2}", datatiercal.finepreiceprocal)
    16.             MsgBox("Transaction was saved")
    17.         Catch ex As Exception
    18.             MessageBox.Show(ex.Message)
    19.         End Try
    20.     End Sub
    Last edited by Srut; Dec 17th, 2017 at 11:19 AM.

  12. #12

    Thread Starter
    Member
    Join Date
    Nov 2017
    Posts
    40

    Re: How to make changes on one form that will change information on another form

    here is the book table where i am now working directly with as you guys suggested but the calculation are not being done
    vb.net Code:
    1. Public Class Book_Table
    2.     Private Shared Instance As Book_Table
    3.     Public Shared ReadOnly Property BoolTableInstance() As Book_Table
    4.         Get
    5.             If Instance Is Nothing Then
    6.                 Instance = New Book_Table()
    7.             End If
    8.             Return Instance
    9.         End Get
    10.     End Property
    11.  
    12.     Public Sub Copiescount()
    13.         If Transactions_Table.butclcik = True Then
    14.             CopiesTextBox.Text = Double.Parse((CopiesTextBox.Text = CopiesTextBox.Text) - 1)
    15.             Me.TableAdapterManager.UpdateAll(Me.LibrarymanagementDataSet2)
    16.             Me.Book_TableTableAdapter.Update(Me.LibrarymanagementDataSet2)
    17.         End If
    18.     End Sub
    19.  
    20.     Private Sub Book_TableBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles Book_TableBindingNavigatorSaveItem.Click
    21.         Me.Validate()
    22.         Me.Book_TableBindingSource.EndEdit()
    23.         Me.TableAdapterManager.UpdateAll(Me.LibrarymanagementDataSet2)
    24.  
    25.     End Sub
    26.  
    27.  
    28.     Private Sub AddButton_Click(sender As Object, e As EventArgs) Handles AddButton.Click
    29.         Try
    30.             Book_TableBindingSource.AddNew()
    31.         Catch ex As Exception
    32.             MessageBox.Show(ex.Message)
    33.         End Try
    34.     End Sub
    35.  
    36.     Private Sub SaveButton_Click(sender As Object, e As EventArgs) Handles SaveButton.Click
    37.         Try
    38.             Me.Validate()
    39.             Me.Book_TableBindingSource.EndEdit()
    40.             Me.TableAdapterManager.UpdateAll(Me.LibrarymanagementDataSet2)
    41.             Book_NameTextBox.Select()
    42.             MsgBox("Book Was Saved")
    43.         Catch ex As Exception
    44.             MessageBox.Show(ex.Message)
    45.         End Try
    46.     End Sub
    47.  
    48.     Private Sub DeleteButton_Click(sender As Object, e As EventArgs) Handles DeleteButton.Click
    49.         Try
    50.             Dim result As Integer = MessageBox.Show("Are you sure you want to delete this Book", "Delete Book", MessageBoxButtons.YesNo)
    51.             If result = DialogResult.No Then
    52.                 MessageBox.Show("Book was not deleted")
    53.             ElseIf result = DialogResult.Yes Then
    54.                 Book_TableBindingSource.RemoveCurrent()
    55.                 MessageBox.Show("The Book was deleted")
    56.             End If
    57.  
    58.         Catch ex As Exception
    59.             MessageBox.Show(ex.Message)
    60.         End Try
    61.  
    62.     End Sub
    63.  
    64.     Private Sub Update_Book_Click(sender As Object, e As EventArgs) Handles Update_Book.Click
    65.         Try
    66.  
    67.             Me.Validate()
    68.             Me.Book_TableBindingSource.EndEdit()
    69.             Me.TableAdapterManager.UpdateAll(Me.LibrarymanagementDataSet2)
    70.             MsgBox("Book was updated")
    71.         Catch ex As Exception
    72.             MessageBox.Show(ex.Message)
    73.         End Try
    74.  
    75.     End Sub
    76.  
    77.     Private Sub Book_Table_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
    78.         Instance = Nothing
    79.     End Sub
    80.  
    81.     Private Sub View_Books_Click(sender As Object, e As EventArgs) Handles View_Books.Click
    82.         Dim ViewBooksub As ViewBook = ViewBook.ViewBookInstance
    83.         ViewBooksub.Show()
    84.         ViewBooksub.Focus()
    85.     End Sub
    86.  
    87.     Private Sub Book_TableBindingNavigatorSaveItem_Click_1(sender As Object, e As EventArgs) Handles Book_TableBindingNavigatorSaveItem.Click
    88.         Me.Validate()
    89.         Me.Book_TableBindingSource.EndEdit()
    90.         Me.TableAdapterManager.UpdateAll(Me.LibrarymanagementDataSet2)
    91.  
    92.     End Sub
    93.  
    94.     Private Sub Book_TableBindingNavigatorSaveItem_Click_2(sender As Object, e As EventArgs) Handles Book_TableBindingNavigatorSaveItem.Click
    95.         Me.Validate()
    96.         Me.Book_TableBindingSource.EndEdit()
    97.         Me.TableAdapterManager.UpdateAll(Me.LibrarymanagementDataSet2)
    98.  
    99.     End Sub
    100.  
    101.     Private Sub Book_Table_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    102.         'TODO: This line of code loads data into the 'LibrarymanagementDataSet2.Book_Table' table. You can move, or remove it, as needed.
    103.         Me.Book_TableTableAdapter.Fill(Me.LibrarymanagementDataSet2.Book_Table)
    104.         Validate()
    105.         Book_TableBindingSource.EndEdit()
    106.         TableAdapterManager.UpdateAll(Me.LibrarymanagementDataSet2)
    107.     End Sub
    108.  
    109.     Private Sub Book_ID2ToolStripButton_Click(sender As Object, e As EventArgs) Handles Book_ID2ToolStripButton.Click
    110.         Try
    111.             Me.Book_TableTableAdapter.Book_ID2(Me.LibrarymanagementDataSet2.Book_Table, CType(Param1ToolStripTextBox.Text, Integer))
    112.         Catch ex As System.Exception
    113.             System.Windows.Forms.MessageBox.Show(ex.Message)
    114.         End Try
    115.  
    116.     End Sub
    117.  
    118.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    119.         Try
    120.             Book_TableBindingNavigator.MovePreviousItem.PerformClick()
    121.         Catch ex As Exception
    122.             MsgBox(ex.Message)
    123.         End Try
    124.     End Sub
    125.  
    126.  
    127.  
    128.     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    129.         Try
    130.             Book_TableBindingNavigator.MoveNextItem.PerformClick()
    131.         Catch ex As Exception
    132.             MsgBox(ex.Message)
    133.         End Try
    134.     End Sub
    135.  
    136.     Private Sub CopiesTextBox_TextChanged(sender As Object, e As EventArgs) Handles CopiesTextBox.TextChanged
    137.  
    138.     End Sub
    139.  
    140.  
    141.  
    142.  
    143. End Class


    here is the transaction table.


    vb.net Code:
    1. Public Class Transactions_Table
    2.     Private Shared Instance As Transactions_Table
    3.     Public Shared ReadOnly Property TransactionsTableInstance() As Transactions_Table
    4.         Get
    5.             If Instance Is Nothing Then
    6.                 Instance = New Transactions_Table
    7.             End If
    8.             Return Instance
    9.         End Get
    10.     End Property
    11.     Private Sub Transaction_TableBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs)
    12.         Me.Validate()
    13.         Me.Transaction_TableBindingSource.EndEdit()
    14.         Me.TableAdapterManager.UpdateAll(Me.LibrarymanagementDataSet2)
    15.  
    16.     End Sub
    17.  
    18.     Private Sub Transactions_Table_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    19.         Me.Book_TableTableAdapter1.Fill(Me.LibrarymanagementDataSet2.Book_Table)
    20.         'TODO: This line of code loads data into the 'LibrarymanagementDataSet2.Transaction_Table' table. You can move, or remove it, as needed.
    21.         Me.Transaction_TableTableAdapter.Fill(Me.LibrarymanagementDataSet2.Transaction_Table)
    22.     End Sub
    23.  
    24.  
    25.  
    26.     Public Shared butclcik As Boolean
    27.     Private Sub SaveButton_Click(sender As Object, e As EventArgs) Handles SaveButton.Click
    28.         Try
    29.             butclcik = True
    30.  
    31.  
    32.             Dim datatiercal As DataTier = New DataTier(Due_DateDateTimePicker.Value.Date, Return_DateDateTimePicker.Value.Date)
    33.             CostTextBox.Text = String.Format("{0:c2}", datatiercal.finepreiceprocal)
    34.             DayOverduetextbox.Text = datatiercal.Daysoverdueprocal
    35.             Transaction_TableDataGridView.Columns(7).DefaultCellStyle.Format = "c"
    36.             Me.Validate()
    37.             Me.Transaction_TableBindingSource.EndEdit()
    38.             Me.Book_TableTableAdapter1.Update(Me.LibrarymanagementDataSet2)
    39.             Me.TableAdapterManager.UpdateAll(Me.LibrarymanagementDataSet2)
    40.             CostTextBox.Text = String.Format("{0:c2}", datatiercal.finepreiceprocal)
    41.             MsgBox("Transaction was saved")
    42.         Catch ex As Exception
    43.             MessageBox.Show(ex.Message)
    44.         End Try
    45.     End Sub
    Last edited by Srut; Dec 17th, 2017 at 11:34 AM.

  13. #13

    Thread Starter
    Member
    Join Date
    Nov 2017
    Posts
    40

    Re: How to make changes on one form that will change information on another form

    Quote Originally Posted by wes4dbt View Post
    It's hard for me to even respond to this because it really doesn't make sense. At least not to me.
    this code,
    Code:
        Public butclcik As Boolean
        Private Sub SaveButton_Click(sender As Object, e As EventArgs) Handles SaveButton.Click
            butclcik = True
            Try
                If butclcik = True Then
                    Double.Parse((boktble.Book_TableDataGridView.Columns(6).ValueType = boktble.Book_TableDataGridView.Columns(6).ValueType) - 1)
                End If
    Doesn't make sense. butclcik is ALWAYS true when you click the Savebutton, it really doesn't serve any purpose.

    I can't really help with working directly with the Book table without more information.

    I'm guessing that the dgv column 6 is bound to a field in the Book table. Are you saying you want to subtract 1 from the value in that field for EVERY row in that table? If so you can do that by manually cycling through the Me.LibrarymanagementDataSet2.Book_Table datatable using a For/Next loop or add an Update Query to the Book_TableTableAdapter in the LibrarymanagementDataSet2 dataset.
    ?
    ok i just read what you wrote completely if i make an update query and display this as a datagridview it will place the updated information for the number of copies after i have made a transaction in my transaction table?

  14. #14

    Thread Starter
    Member
    Join Date
    Nov 2017
    Posts
    40

    Re: How to make changes on one form that will change information on another form

    Quote Originally Posted by wes4dbt View Post
    It's hard for me to even respond to this because it really doesn't make sense. At least not to me.
    this code,
    Code:
        Public butclcik As Boolean
        Private Sub SaveButton_Click(sender As Object, e As EventArgs) Handles SaveButton.Click
            butclcik = True
            Try
                If butclcik = True Then
                    Double.Parse((boktble.Book_TableDataGridView.Columns(6).ValueType = boktble.Book_TableDataGridView.Columns(6).ValueType) - 1)
                End If
    Doesn't make sense. butclcik is ALWAYS true when you click the Savebutton, it really doesn't serve any purpose.

    I can't really help with working directly with the Book table without more information.

    I'm guessing that the dgv column 6 is bound to a field in the Book table. Are you saying you want to subtract 1 from the value in that field for EVERY row in that table? If so you can do that by manually cycling through the Me.LibrarymanagementDataSet2.Book_Table datatable using a For/Next loop or add an Update Query to the Book_TableTableAdapter in the LibrarymanagementDataSet2 dataset.
    how would i go about subtracting 1 from the copies in the book table after i make a transaction in the transaction table and click save. i thought after i click save in the transaction table and make butclick true then it would preform the expression to subtract 1 from copies in the book table after it checks if butclcik is true. but you are telling me after i click it and butclick will alsway be true so i cant use it this way. how would i go about make it so every time i click save in the transaction table the expression to subtract 1 from copies is done in the book table.

  15. #15
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    3,588

    Re: How to make changes on one form that will change information on another form

    Here's an example, you will have to change the names to work with your system.
    Code:
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            Dim row As DataRow = Me.BooksDBDataSet.Books.FindByBookId(3)
            If Not row Is Nothing Then
                row("copies") = CInt(row("copies")) - 1
                Me.BooksTableAdapter.Update(Me.BooksDBDataSet.Books)
            End If
        End Sub
    You will have to replace Me.BooksDBDataSet.Books.FindByBookId(3) the "3" with the current BookId value in the transaction table.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width