Results 1 to 16 of 16

Thread: [RESOLVED] Updating DatagridView Code

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    293

    Resolved [RESOLVED] Updating DatagridView Code

    Hi all

    i have this bit of code for searching for a number from a db and returning it to a datagridview

    vb.net Code:
    1. Dim con5 As New OleDb.OleDbConnection
    2.         Dim ds5 As New DataSet
    3.         Dim da5 As OleDb.OleDbDataAdapter
    4.         Dim SQL5 As String
    5.         con5.ConnectionString = My.Settings.GoodsinConnect
    6.         con5.Open()
    7.         ds5.Clear()
    8.         SQL5 = "SELECT * FROM [ReceiptLines] WHERE [PartNo] ='" & Partnumber & "'"
    9.         da5 = New OleDb.OleDbDataAdapter(SQL5, con5)
    10.         da5.Fill(ds5, "ReceiptLines")
    11.         dgvPartNumbers.DataSource = ds5.Tables(0).DefaultView
    12.         con5.Close()

    This works fine.

    However when a user updates a record that is shown via another form. When they are returned back to the main form i want the record to be updated.

    So for now i put a simple timer in that looks when the record is updated and a value is changed and when it has then it triggers

    vb.net Code:
    1. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    2.         If RefreshData = 1 Then
    3.              btnSearch_Click(Me, EventArgs.Empty)
    4.             RefreshData = 0
    5.         End If
    6.     End Sub

    I've also tried:

    vb.net Code:
    1. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    2.         If RefreshData = 1 Then
    3.              btnSearch.PerformClick()
    4.             RefreshData = 0
    5.         End If
    6.     End Sub


    Although it goes through the code like it would it doesnt actually update the datagridview.

    However if i press the button on the form it updates it.


    Can anyone help me out here.

    Thanks
    Alex

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Updating DatagridView Code

    is btnSearch on the same form as timer1?
    the PerformClick method is the correct one

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    293

    Re: Updating DatagridView Code

    Quote Originally Posted by .paul. View Post
    is btnSearch on the same form as timer1?
    the PerformClick method is the correct one
    Hi .paul.

    Yes timer1 and btnsearch are on the same form. The performclick method wont even go through the code of the button.

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Updating DatagridView Code

    where on the form is btnSearch?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    293

    Re: Updating DatagridView Code

    Quote Originally Posted by .paul. View Post
    where on the form is btnSearch?
    Ahhhh would it make a difference if it was inside a split panel container?

    The Search box and button are inside one of these

    I have attached a picture for reference. The form is split into two , datagridview in bottom half.
    Then the top half is then split into two again. search on one side and the book now button on the other
    Last edited by crampz; Nov 19th, 2012 at 03:26 PM.

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Updating DatagridView Code

    [containerName].btnSearch.performclick should do it, but if calling the handler manually ran the code + it didn't work, there must be another problem too...

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    293

    Re: Updating DatagridView Code

    Quote Originally Posted by .paul. View Post
    [containerName].btnSearch.performclick should do it, but if calling the handler manually ran the code + it didn't work, there must be another problem too...
    I dont get the option of "btnsearch" when i type in the container name.

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Updating DatagridView Code

    ok. i tried a new project with a splitcontainer with a button + it doesn't need containerName.

    at the point in your app's execution that the performclick is invoked, is there a dialog open?, as the form wouldn't be active with an active dialog open

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Updating DatagridView Code

    i'd guess the other problem is that the part number textbox is empty at the time you click the button

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    293

    Re: Updating DatagridView Code

    Quote Originally Posted by .paul. View Post
    i'd guess the other problem is that the part number textbox is empty at the time you click the button
    MOTHER F******

    I have found the problem

    I have the form load inside a parent form. So i tried it without. and btnSearch.PerformClick() works and updates. So now the question is why and how do i get it to work when the form is loaded in a parent container
    Last edited by crampz; Nov 18th, 2012 at 03:05 PM.

  11. #11
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Updating DatagridView Code

    the form was an mdichild?

    i don't get it. can you show me the code?

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    293

    Re: Updating DatagridView Code

    Quote Originally Posted by .paul. View Post
    the form was an mdichild?

    i don't get it. can you show me the code?
    Sorry.

    I have a Parentform which is a MDIContainer. then i have this form load inside it using:

    vb.net Code:
    1. Private Sub tslScanItems_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tslScanItems.Click
    2.         Dim frm As New ScanItems
    3.         frm.MdiParent = Me
    4.         frm.Show()
    5.     End Sub

    So instead of having the parentform load at startup i changed it to this form and when i went through everything it worked. When i go back to having it load inside the parent form it doesn't work.

  13. #13
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Updating DatagridView Code

    ok. i tested it with an mdi form + a child form with a splitcontainer + a timer, + a button... all working as expected.
    you're sure the button isn't clicked?

  14. #14
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Updating DatagridView Code

    i've done some more testing + the only possibility is that you're referring to a default instance of your mdi child form. here's an example:

    Code:
    'this is the mdiParent form
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim frm As New Form2
            frm.MdiParent = Me
            frm.Show()
        End Sub
    
    End Class
    Code:
    'this is the mdiChild form
    Public Class Form2
    
        Public upDated As Integer = 0
    
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            If upDated = 1 Then
                Button1.PerformClick()
                upDated = 0
            End If
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            MsgBox("")
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim frm As New Form3(Me)
            frm.ShowDialog()
        End Sub
    
    End Class

    Code:
    'this is the edit dialog
    Public Class Form3
    
        Dim ownerInstance As Form2
    
        Public Sub New(ByVal ownerInstance As Form2)
            InitializeComponent()
            Me.ownerInstance = ownerInstance
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            ownerInstance.upDated = 1
        End Sub
    
    End Class

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    293

    Re: Updating DatagridView Code

    Ok Ok . I now have to thank you so much.

    I don't know why. But i bascially copied your parts into my setup and it works. T

    Thank you for everything and all your help.

  16. #16
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: [RESOLVED] Updating DatagridView Code

    a new instance of Form2 can't be referred to by the name Form2, which is the base form + not the dynamic instance of that form

Posting Permissions

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



Click Here to Expand Forum to Full Width