-
Nov 18th, 2012, 01:57 PM
#1
Thread Starter
Hyperactive Member
[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:
Dim con5 As New OleDb.OleDbConnection Dim ds5 As New DataSet Dim da5 As OleDb.OleDbDataAdapter Dim SQL5 As String con5.ConnectionString = My.Settings.GoodsinConnect con5.Open() ds5.Clear() SQL5 = "SELECT * FROM [ReceiptLines] WHERE [PartNo] ='" & Partnumber & "'" da5 = New OleDb.OleDbDataAdapter(SQL5, con5) da5.Fill(ds5, "ReceiptLines") dgvPartNumbers.DataSource = ds5.Tables(0).DefaultView 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:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick If RefreshData = 1 Then btnSearch_Click(Me, EventArgs.Empty) RefreshData = 0 End If End Sub
I've also tried:
vb.net Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick If RefreshData = 1 Then btnSearch.PerformClick() RefreshData = 0 End If 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
-
Nov 18th, 2012, 02:01 PM
#2
Re: Updating DatagridView Code
is btnSearch on the same form as timer1?
the PerformClick method is the correct one
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 18th, 2012, 02:07 PM
#3
Thread Starter
Hyperactive Member
Re: Updating DatagridView Code
Originally Posted by .paul.
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.
-
Nov 18th, 2012, 02:12 PM
#4
Re: Updating DatagridView Code
where on the form is btnSearch?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 18th, 2012, 02:16 PM
#5
Thread Starter
Hyperactive Member
Re: Updating DatagridView Code
Originally Posted by .paul.
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.
-
Nov 18th, 2012, 02:20 PM
#6
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...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 18th, 2012, 02:31 PM
#7
Thread Starter
Hyperactive Member
Re: Updating DatagridView Code
Originally Posted by .paul.
[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.
-
Nov 18th, 2012, 02:38 PM
#8
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 18th, 2012, 02:40 PM
#9
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 18th, 2012, 03:02 PM
#10
Thread Starter
Hyperactive Member
Re: Updating DatagridView Code
Originally Posted by .paul.
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.
-
Nov 18th, 2012, 03:11 PM
#11
Re: Updating DatagridView Code
the form was an mdichild?
i don't get it. can you show me the code?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 18th, 2012, 03:18 PM
#12
Thread Starter
Hyperactive Member
Re: Updating DatagridView Code
Originally Posted by .paul.
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:
Private Sub tslScanItems_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tslScanItems.Click
Dim frm As New ScanItems
frm.MdiParent = Me
frm.Show()
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.
-
Nov 18th, 2012, 03:30 PM
#13
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?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 18th, 2012, 04:04 PM
#14
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 18th, 2012, 04:17 PM
#15
Thread Starter
Hyperactive Member
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.
-
Nov 18th, 2012, 04:25 PM
#16
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|