Adam Posted February 20, 2004 Posted February 20, 2004 (edited) I have an array containing all the item names. I just need to understand how to get the variable over to the other form. thanks Edited February 20, 2004 by Adam Quote I feel the pivitol moment of failure approaching.
gabru Posted February 20, 2004 Posted February 20, 2004 Just add a public property to your new form-class and if you create an instance then drop the listbox in it. example: 'This is the new form wich gets the lisbox Public Class Form2 Inherits System.Windows.Forms.Form Public lb as Listbox End Class 'This is the call to the new form Dim newForm as new Form2 newForm.lb = listbox1 newForm.show() Quote sometimes I blog... http://michal.grafix.at
Adam Posted February 20, 2004 Author Posted February 20, 2004 The first code you posted, I understand. But the second, I don't. I have the forms created already. I don't understand the dimming of a New Form2. and the newForm.show().. I'm doing this on a button click. I'm clicking a button and then populating a listbox on another form with an array variable i've got on the form where I clicked the button. I'm just so confussed. Thanks for helping. Quote I feel the pivitol moment of failure approaching.
gabru Posted February 20, 2004 Posted February 20, 2004 so if your form is already opend you can just assign the listbox to the form you want. the one thing you need ist to create a public property or a method in the new form which you can call later. Quote sometimes I blog... http://michal.grafix.at
Adam Posted February 20, 2004 Author Posted February 20, 2004 You lost me. Quote I feel the pivitol moment of failure approaching.
gabru Posted February 20, 2004 Posted February 20, 2004 please be so good and post your code and try again to explain what you want. thx Quote sometimes I blog... http://michal.grafix.at
Adam Posted February 20, 2004 Author Posted February 20, 2004 Think of this as opening your address book in Outlook. You have not data in the To: box. So you click a button and it opens your address window. You select the address you want from the right lstbox and click "add" and it populates the left lst box with your selections. You can add and remove other items at will. When your done you click a "Done" button and your left lstbox data is copied to the lstbox on the email form. (this isn't an email form. But it's a similar function,.. adding the addresses) Private Sub lnklblAddCust_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnklblAddCust.LinkClicked Dim OpenForm As frmAddCust OpenForm = New frmAddCust() OpenForm.ShowDialog(Me) End Sub Once the AddMaterial button is clicked I open this form and do stuff: Private Sub btnDone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDone.Click Dim lstbox(lstboxMaterial.Items.Count - 1) As String Dim val As Integer For val = 0 To lstboxMaterial.Items.Count - 1 lstbox(val) = lstboxMaterial.Items.Item(val) Next Me.Close() End Sub Quote I feel the pivitol moment of failure approaching.
gabru Posted February 20, 2004 Posted February 20, 2004 hmm .. now i am confused too .. but i think its still the same i have written to you. add the following line to your frmAddCust form Public parentForm as Form now add this line when opening the form OpenForm.parentForm = me and now you can easily use all properties and methods of the parentform. example Private Sub btnDone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDone.Click Dim lstbox(lstboxMaterial.Items.Count - 1) As String Dim val As Integer For val = 0 To lstboxMaterial.Items.Count - 1 lstbox(val) = lstboxMaterial.Items.Item(val) Next 'now we can use all properties and methods of parentform Me.parentform.width = 500 Me.Close() End Sub hope you know what i mean Quote sometimes I blog... http://michal.grafix.at
Adam Posted February 20, 2004 Author Posted February 20, 2004 LOL my bad... posted the wrong code. But it's still close to the same... Private Sub btnAddMaterial_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddMaterial.Click Dim OpenForm As frmMaterialSelect OpenForm = New frmMaterialSelect() OpenForm.ShowDialog(Me) End Sub If there is a more right way to do this i'm all ears. I've extremely new to VB and i'm trying to learn as I go. Quote I feel the pivitol moment of failure approaching.
gabru Posted February 20, 2004 Posted February 20, 2004 from my point of view its the right way Quote sometimes I blog... http://michal.grafix.at
I Schobert Posted February 20, 2004 Posted February 20, 2004 Adam, I was reading through the previous messages in this thread and I have to say that, besides confusing each other, you also lost me. I would like to help you, it seems you don't have a major issue here. Could you do me a favor and start fresh. Please state what you need, what you got, and where the problem is. Thanks... :) Quote IS
Adam Posted February 20, 2004 Author Posted February 20, 2004 Sure. Baby steps. I need baby steps. :) On one form I have an "Add Material" button and a listbox under it(blank). I click the Add Material button and it brings up a new form. This form has 2 listboxes, one on the left and the other on the right. The one on the left is populated with all the Material in a MDB. The one on the right is empty. I select from the left lstbox items I want to add to a WorkOrder Materail list (lstbox on the left). Once all item used on the job are selected and added to the right lstbox I click a done button. I want the contents of the right lstbox to populate the lstbox on the previous form. I stored all the items of the right lstbox into an array. I can display them in a 3rd lstbox (did this as a test). So I have the items saved into this array and ready to populate the lstbox on the first form. Quote I feel the pivitol moment of failure approaching.
gabru Posted February 20, 2004 Posted February 20, 2004 i think everyone is confused cause it is friday and the weekend is coming ..... ;) Quote sometimes I blog... http://michal.grafix.at
gabru Posted February 20, 2004 Posted February 20, 2004 so do everything i wrote to you. write a method in the mainForm which fills the listbox with the values of the array and call it then when the done button is pressed. thats it. Quote sometimes I blog... http://michal.grafix.at
I Schobert Posted February 20, 2004 Posted February 20, 2004 Ok, so let me try on this Friday :) you initialize this form like this: OpenForm = New frmMaterialSelect() OpenForm.ShowDialog(Me) Try this instead: OpenForm = New frmMaterialSelect(Me) OpenForm.ShowDialog() in the frmMaterialSelect, add the following to the initialize section, right below the Public Sub New () method Private CallerForm as NAMEOFYOURCALLINGFORM Public Sub New (frm as NAMEOFYOURCALLINGFORM) MyClass.New() CallerForm = frm End Sub In your Done button, loop through your array and fill the list in the caller form by using this reference, like: CallerForm.ListBox1.[and here whatever you want to do to it] Does this work? It would be cool if get this over with during this week :) Quote IS
I Schobert Posted February 20, 2004 Posted February 20, 2004 Sorry gabru, I didn't see that you were responding ... Quote IS
gabru Posted February 20, 2004 Posted February 20, 2004 no problem .. i just summerized it without code ;) so i think its good for him to see some code. Good idea to provide the listview as a param in the constructor! Quote sometimes I blog... http://michal.grafix.at
Adam Posted February 20, 2004 Author Posted February 20, 2004 ok. Going to give it go. May take me abit to get back. I'm here at work and well.. i got to do some type of work besides playing with vb. brb asap. Quote I feel the pivitol moment of failure approaching.
Adam Posted February 20, 2004 Author Posted February 20, 2004 OpenForm = New frmMaterialSelect(Me) OpenForm.ShowDialog() (Me) is underlinded saying.... To many arguments to 'Public Sub New()' Quote I feel the pivitol moment of failure approaching.
gabru Posted February 20, 2004 Posted February 20, 2004 maybe there is already a sub called new available. take a look . maybe in the designer generated code. Quote sometimes I blog... http://michal.grafix.at
I Schobert Posted February 20, 2004 Posted February 20, 2004 Adam, Read carefully through my message. Did you see the section telling you to create this in your called form: Private CallerForm as NAMEOFYOURCALLINGFORM Public Sub New (frm as NAMEOFYOURCALLINGFORM) MyClass.New() CallerForm = frm End Sub That will give you an overloaded sub new with the parameter. And gabru, of course there is already a Sub New, there is always one when you create a form. This Sub New is generated automatically and takes no parameters.... Quote IS
Adam Posted February 20, 2004 Author Posted February 20, 2004 Got it. yahooooooooo!!!!!!!!! Now i'm going to study this for about 3hrs so i'll know what the hell is going on. Thanks ya'll Quote I feel the pivitol moment of failure approaching.
gabru Posted February 20, 2004 Posted February 20, 2004 i know schobert :) just wanted to have him take a closer look Quote sometimes I blog... http://michal.grafix.at
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.