473,804 Members | 3,312 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

updating control on form2 from form1

Hi.

I have 2 forms:
form1
form2

On Form2 I have a listbox and a button. When I click the button it calls a
function from form1 and within that function it updates the listbox on
form2.
My problem is I don't see the items added to the listbox unless I use
form2.show() to open another instance of Form2.

I'm sure this is something simple.

Thanks.

Rob
May 19 '06 #1
3 2484
Rob,

The function on form1 needs a reference to the current form2.

I suspect that the function is creating a new instance of form2 and not
using the current instance.

You might want to post your code if you can't get it working.

Kerry Moorman
"R. Harris" wrote:
Hi.

I have 2 forms:
form1
form2

On Form2 I have a listbox and a button. When I click the button it calls a
function from form1 and within that function it updates the listbox on
form2.
My problem is I don't see the items added to the listbox unless I use
form2.show() to open another instance of Form2.

I'm sure this is something simple.

Thanks.

Rob

May 19 '06 #2
I'm not sure I understand what 'The function on form1 needs a reference to
the current form2' means.
Ok, here is a portion of my code - The last if/else statement on Form1 is
where I assign a value to the listbox on Form2:

FORM2---------------------------------------
Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2.Click
Dim searchButton As String, textBoxString As String, deleteRecord As
Boolean
deleteRecord = True
searchButton = "SearchButt on"
textBoxString = txtName.Text.To Upper
Form1.FindMatch (searchButton, textBoxString, True)
End Sub
FORM1---------------------------------------
Public Function FindMatch(ByVal whatButton As String, Optional ByVal
SearchPar As String = "", Optional ByVal deleteRecord As Boolean = False)
'call sub to get record location.
openDatForRecor dLocation()
' Clear the contents of the text box
TextBox1.Text = ""
' Open the file to read from and assign each line to string array called
readText()
Dim readText() As String
If closeApp = False Then
readText = File.ReadAllLin es(pathToRecord s)
'Use lineOfText in the For Each to iterate thru the string array
readText assigning matches to lineOfText.
Dim lineOfText As String
'matchesFound will be used to store matching results to display in
results text box or populate the combo box on form open
Dim matchesFound As String = ""
'countResults will be used to track the number of results found
Dim CountResults As Integer
'countRecords will be used to track the number of records in the
file
Dim countRecords As Integer
'Use a boolean variable to determine whether or not to process the
rest of the function if
'whatButton is equal to FormOpenCombo
Dim finishFunction As Boolean
For Each lineOfText In readText
'Count number of total records in the file
countRecords += 1
If lineOfText.ToUp per.Contains(Se archPar) Then
If Not lineOfText.Star tsWith("[") And Not
lineOfText.Ends With("]") Then
'Count the number of results found
CountResults += 1
'Sort the array
Array.Sort(read Text)
If deleteRecord = False Then
' if not deleting a record do this
'For every match found, assign to matchesFound
variable with a carriage return.
matchesFound += lineOfText & vbCrLf
finishFunction = True
Else
'HERE IS WHERE I AM HAVING THE PROBLEM
'If deleting a record then do this
Form2.lstResult s.Items.Add(lin eOfText)
finishFunction = False
End If
End If

If i add change the above to this:

Form2.lstResult s.Items.Add(lin eOfText)
Form2.lstResult s.Show()
finishFunction = False

Form2 will reopen with the original behind it, showing lstResults listbox
with the value of lineOfText.


"Kerry Moorman" <Ke**********@d iscussions.micr osoft.com> wrote in message
news:3E******** *************** ***********@mic rosoft.com...
Rob,

The function on form1 needs a reference to the current form2.

I suspect that the function is creating a new instance of form2 and not
using the current instance.

You might want to post your code if you can't get it working.

Kerry Moorman
"R. Harris" wrote:
Hi.

I have 2 forms:
form1
form2

On Form2 I have a listbox and a button. When I click the button it calls
a
function from form1 and within that function it updates the listbox on
form2.
My problem is I don't see the items added to the listbox unless I use
form2.show() to open another instance of Form2.

I'm sure this is something simple.

Thanks.

Rob

May 19 '06 #3
Rob,

Is that VS2005's new feature of referring to a form? I don't use that
technique, so I can't really comment on it.

Maybe you could do a Form2.Refresh to get the data to show up in the
listbox. Or maybe a lstResults.Refr esh.

Kerry Moorman
"R. Harris" wrote:
I'm not sure I understand what 'The function on form1 needs a reference to
the current form2' means.
Ok, here is a portion of my code - The last if/else statement on Form1 is
where I assign a value to the listbox on Form2:

FORM2---------------------------------------
Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2.Click
Dim searchButton As String, textBoxString As String, deleteRecord As
Boolean
deleteRecord = True
searchButton = "SearchButt on"
textBoxString = txtName.Text.To Upper
Form1.FindMatch (searchButton, textBoxString, True)
End Sub
FORM1---------------------------------------
Public Function FindMatch(ByVal whatButton As String, Optional ByVal
SearchPar As String = "", Optional ByVal deleteRecord As Boolean = False)
'call sub to get record location.
openDatForRecor dLocation()
' Clear the contents of the text box
TextBox1.Text = ""
' Open the file to read from and assign each line to string array called
readText()
Dim readText() As String
If closeApp = False Then
readText = File.ReadAllLin es(pathToRecord s)
'Use lineOfText in the For Each to iterate thru the string array
readText assigning matches to lineOfText.
Dim lineOfText As String
'matchesFound will be used to store matching results to display in
results text box or populate the combo box on form open
Dim matchesFound As String = ""
'countResults will be used to track the number of results found
Dim CountResults As Integer
'countRecords will be used to track the number of records in the
file
Dim countRecords As Integer
'Use a boolean variable to determine whether or not to process the
rest of the function if
'whatButton is equal to FormOpenCombo
Dim finishFunction As Boolean
For Each lineOfText In readText
'Count number of total records in the file
countRecords += 1
If lineOfText.ToUp per.Contains(Se archPar) Then
If Not lineOfText.Star tsWith("[") And Not
lineOfText.Ends With("]") Then
'Count the number of results found
CountResults += 1
'Sort the array
Array.Sort(read Text)
If deleteRecord = False Then
' if not deleting a record do this
'For every match found, assign to matchesFound
variable with a carriage return.
matchesFound += lineOfText & vbCrLf
finishFunction = True
Else
'HERE IS WHERE I AM HAVING THE PROBLEM
'If deleting a record then do this
Form2.lstResult s.Items.Add(lin eOfText)
finishFunction = False
End If
End If

If i add change the above to this:

Form2.lstResult s.Items.Add(lin eOfText)
Form2.lstResult s.Show()
finishFunction = False

Form2 will reopen with the original behind it, showing lstResults listbox
with the value of lineOfText.


"Kerry Moorman" <Ke**********@d iscussions.micr osoft.com> wrote in message
news:3E******** *************** ***********@mic rosoft.com...
Rob,

The function on form1 needs a reference to the current form2.

I suspect that the function is creating a new instance of form2 and not
using the current instance.

You might want to post your code if you can't get it working.

Kerry Moorman
"R. Harris" wrote:
Hi.

I have 2 forms:
form1
form2

On Form2 I have a listbox and a button. When I click the button it calls
a
function from form1 and within that function it updates the listbox on
form2.
My problem is I don't see the items added to the listbox unless I use
form2.show() to open another instance of Form2.

I'm sure this is something simple.

Thanks.

Rob


May 19 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3779
by: nic | last post by:
Hi I have two forms form1 and form2. I am trying to get all the data entered in form1 to be updated to the table on an event. ie. when I click the button to load form2, I need the data from form1 to exist in the table for relationship reasons. form2 works fine if the records displayed in form1 already exist in the table, ie form1 was closed then re-opened or moving between records will also write the data to the table. But if I have...
0
1396
by: Art Guerra | last post by:
Any tips or information would be most appreciated! Here is my scenario simplified: I have a main application form (Form1) and on that form is a listView control. On a separate form (Form2), the user is able to select a folder using a folderBrowser control. I want the paths to all files to be added to the listView control on Form1. My question lies around what thread should perform the item additions. Currently, on Form2, I referenced...
4
1389
by: jcrouse | last post by:
I have an app with form1 and form2. Form1 has a label control. Form2 has a checkbox and OK button. By default the label on form1 is hidden. When I lauch my app form1 is the default. I right click on the form and select "Add Labels" from the context menu. This takes me to form2 where I can then select the checkbox if I want to turn on the label back on form1. This works great. I then select the "OK" button on form2 and executed the following code...
4
13969
by: Carlos | last post by:
In VB6 I was able to accessa control like a progressbar form a different form, for example frm1.progressbar1.value =XXX but now how can I do that in VB.NET Thanks
2
4720
by: Tom | last post by:
Let's say I have written a VB.NET user control, with the following components: MyControl.sln MyUserControl.vb (user control) Form1 (Windows Form) Form2 (Windows Form) Now, lets say that within the MyUserControl I have a public function that can be called, and that function causes the Form1 form to load in
6
2754
by: Mat | last post by:
Dear all, What I want to do is be able to use a string to refer to a control on a subform. IE: Forms!("Form1!form2!controlA").name or
2
2846
by: Svein Erik | last post by:
C# 2.0 How can i update my progress bar on Form1, from Form2? Form 2 contains a button that is supposed to update the progressbar on Form1 by 5 in value. I can't find out how to do this, please help me with some code samples :) Thanks!
3
3087
by: Luvin lunch | last post by:
Hi All, I have a grid (i.e. continuous form) on Form1, that opens a second form (not a subform) Form2 when the user double clicks on it. On form2 the user can save information. When the user selects Save, I want to reload Form1 because the changes in Form2 will change the order that records should appear on Form1. I have implemented this functionality as follows: Private Sub cmdSave_Click()
1
1491
by: explode | last post by:
My table has 5 columns: Broj iksice, Prezime, Ime, Broj indeksa, Broj pohadjanja. This is the code in the dataset designer VB made it by it self: Private Sub InitClass() Me.columnBroj_iksice = New System.Data.DataColumn("Broj iksice", GetType(Double), Nothing, System.Data.MappingType.Element) Me.columnBroj_iksice.ExtendedProperties.Add("Generator_ColumnPropNameInRow", "Broj_iksice")...
0
9708
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9588
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10085
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3828
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2999
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.