473,382 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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 2461
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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim searchButton As String, textBoxString As String, deleteRecord As
Boolean
deleteRecord = True
searchButton = "SearchButton"
textBoxString = txtName.Text.ToUpper
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.
openDatForRecordLocation()
' 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.ReadAllLines(pathToRecords)
'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.ToUpper.Contains(SearchPar) Then
If Not lineOfText.StartsWith("[") And Not
lineOfText.EndsWith("]") Then
'Count the number of results found
CountResults += 1
'Sort the array
Array.Sort(readText)
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.lstResults.Items.Add(lineOfText)
finishFunction = False
End If
End If

If i add change the above to this:

Form2.lstResults.Items.Add(lineOfText)
Form2.lstResults.Show()
finishFunction = False

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


"Kerry Moorman" <Ke**********@discussions.microsoft.com> wrote in message
news:3E**********************************@microsof t.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.Refresh.

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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim searchButton As String, textBoxString As String, deleteRecord As
Boolean
deleteRecord = True
searchButton = "SearchButton"
textBoxString = txtName.Text.ToUpper
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.
openDatForRecordLocation()
' 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.ReadAllLines(pathToRecords)
'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.ToUpper.Contains(SearchPar) Then
If Not lineOfText.StartsWith("[") And Not
lineOfText.EndsWith("]") Then
'Count the number of results found
CountResults += 1
'Sort the array
Array.Sort(readText)
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.lstResults.Items.Add(lineOfText)
finishFunction = False
End If
End If

If i add change the above to this:

Form2.lstResults.Items.Add(lineOfText)
Form2.lstResults.Show()
finishFunction = False

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


"Kerry Moorman" <Ke**********@discussions.microsoft.com> wrote in message
news:3E**********************************@microsof t.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
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...
0
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...
4
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...
4
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
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...
6
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
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...
3
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...
1
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 =...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.