Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 105,764 VB.NET Programmers for FREE! Ask your question and get quick answers from experts. There are 1,643 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



load data from one form in another form

 
Reply to this topicStart new topic

load data from one form in another form

Hanzie
post 30 Jun, 2008 - 08:32 AM
Post #1


D.I.C Head

**
Joined: 19 Aug, 2007
Posts: 86


My Contributions


hello, i have 2 win-forms.

On one form (form1) i have a simple textbox.
On the other form (form2) i have 1 combobox and 1 textbox.
The combobox and textbox are binded together to a datatable.

What i wan't is that when form2 loads firstly it shows the data from the textbox on form1.
And when i select another value wit the combobox it shows the new data from the textbox on form1 to form2.

My problem is when form2 loads firstly no data is shown in my textbox. Why not???

I have the folowing code:

CODE

My.Forms.Form1.BedrijvenTableAdapter.Fill(My.Forms.Form1.Docregdata2DataSet.Bedrijven)
        My.Forms.Form1.BedrijvenBindingSource.DataSource = My.Forms.Form1.Docregdata2DataSet.Bedrijven
        My.Forms.Form1.PlaatstextBox.DataBindings.Add("text", My.Forms.Form1.BedrijvenBindingSource, "plaats")
        My.Forms.Form1.BedrijvenBindingSource.Position = 1
        My.Forms.Form1.PlaatstextBox.Update()
        Me.TextBox1.Text = My.Forms.Form1.PlaatstextBox.Text


Nothing works? Please help!
User is offlineProfile CardPM

Go to the top of the page


gram999
post 30 Jun, 2008 - 12:12 PM
Post #2


D.I.C Head

**
Joined: 21 Jan, 2008
Posts: 80



Thanked 1 times
My Contributions


Not sure if this will help but this is the way that I pass textbox inputs to Listview between two forms.

For this example assume that there are two forms (Form 1 and Form 2) Form 1 has a textbox and a command button. Form 2 has a ListView and a Command Button.

For each object that I create on Form 1 that is going to pass data to Form 2 I change the modifier in the properties list from "friend to public" So for this example, you have a text box on Form1 that will pass data to a list view on Form 2. So we change the modifier on the text box on Form 1 from "Friend" to "Public" We also change object you are writing to (Listview on Form 2) from "Friend" to "Public" as well. You do not need to do this for the command buttons that initiate the data move. The modifiers are found in the object properties window about half way down Max length and Minimum Size.

Next, I add a new module to my project. (project=> add new item => module)

Generic code for the module to make both forms public would look something like this:

CODE


Module Module1

    Public FForm1 As New Form1()
    Public FForm2 As New Form2()

    Sub Main()
        FForm1.ShowDialog()
    End Sub

End Module



The code on the two forms would look something like this:

Form 1:

CODE


Public Class Form1

    Inherits System.Windows.Forms.Form

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim lvi As New ListViewItem(TextBox1.Text)

        FForm2.Show()
        FForm2.ListView1.Items.Add(lvi)


    End Sub
End Class



**Note that we are using the Public Class on both forms.

Code for Form 2

CODE


Public Class Form2

    Inherits System.Windows.Forms.Form

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        FForm1.TextBox1.Text = TextBox1.Text
        FForm2.Hide()
    End Sub
End Class



In your example you should be able to replace the Listview from the example above with your data grid. Hope this helps.
User is offlineProfile CardPM

Go to the top of the page

modi123_1
post 30 Jun, 2008 - 01:00 PM
Post #3


D.I.C Regular

Group Icon
Joined: 12 Jun, 2008
Posts: 255



Thanked 3 times

Dream Kudos: 100
My Contributions


Check out "shared variables"... and then have your forms send your databack to a shared variable to pass between the two in a third class..

if I have time between work I'll try to jin up an example.


Actually I take it back I have no idea what you mean regarding the interaction of the combobox to the two forms (or the two textboxes). As for getting your value to one or the other.. simply use a property object. Here's the code.

CODE
Public Class Form2
    Public Property SetText() As String
        Get
            Return Me.TextBox1.Text
        End Get
        Set(ByVal value As String)
            Me.TextBox1.Text = value
        End Set
    End Property
End Class


CODE
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim myForm2 As New Form2
        myForm2.SetText = Me.TextBox1.Text
        myForm2.ShowDialog()
    End Sub
End Class


If you explain how you want the combobox to interact I can probably provide more information.

This post has been edited by modi123_1: 30 Jun, 2008 - 01:18 PM
User is offlineProfile CardPM

Go to the top of the page

Hanzie
post 1 Jul, 2008 - 09:12 AM
Post #4


D.I.C Head

**
Joined: 19 Aug, 2007
Posts: 86


My Contributions


Thnx for the reply,

The code you posted works correctly.
But try this:

Put a combobox and textbox on form1. Bind both to a datatable.
Load form2 first when running application, the textbox1 on form2 then must refer to the databinded textbox on form1 but it doesn't show any value.

That's my problem!


QUOTE(modi123_1 @ 30 Jun, 2008 - 01:00 PM) *

Check out "shared variables"... and then have your forms send your databack to a shared variable to pass between the two in a third class..

if I have time between work I'll try to jin up an example.


Actually I take it back I have no idea what you mean regarding the interaction of the combobox to the two forms (or the two textboxes). As for getting your value to one or the other.. simply use a property object. Here's the code.

CODE
Public Class Form2
    Public Property SetText() As String
        Get
            Return Me.TextBox1.Text
        End Get
        Set(ByVal value As String)
            Me.TextBox1.Text = value
        End Set
    End Property
End Class


CODE
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim myForm2 As New Form2
        myForm2.SetText = Me.TextBox1.Text
        myForm2.ShowDialog()
    End Sub
End Class


If you explain how you want the combobox to interact I can probably provide more information.

User is offlineProfile CardPM

Go to the top of the page

modi123_1
post 1 Jul, 2008 - 09:36 AM
Post #5


D.I.C Regular

Group Icon
Joined: 12 Jun, 2008
Posts: 255



Thanked 3 times

Dream Kudos: 100
My Contributions


QUOTE(Hanzie @ 1 Jul, 2008 - 11:12 AM) *

Thnx for the reply,

The code you posted works correctly.
But try this:

Put a combobox and textbox on form1. Bind both to a datatable.
Load form2 first when running application, the textbox1 on form2 then must refer to the databinded textbox on form1 but it doesn't show any value.

That's my problem!



Data bound to a table how? I get why a combobox would have a selected value and a display value.. but what's the relation with the text box?
Second, so when the program runs the first form to come up is form 2? Wouldn't that be form1?
Third, it sounds like a timing issue... if Form2 is already there, then form1 shows up, you need an event that triggers from form 1 to form2 to have it update the value.
User is offlineProfile CardPM

Go to the top of the page

Hanzie
post 1 Jul, 2008 - 09:58 AM
Post #6


D.I.C Head

**
Joined: 19 Aug, 2007
Posts: 86


My Contributions


With the combobox i select a value, textbox1 then shows a belonging value to the selected value from the combobox. For example i select the option "fruit" in the combobox, the textbox1 then displays "apple".

For the example it doesn't mather which form loads first.

Let's say form1 loads first, then i wan't the textbox on this form to show the value "apple" because this is for example the first value from the fruit datatable and so the first value displayed in textbox1 from form1.

But untill now no value is shown in the textbox!?!

You first have to visit the form where the selection can be made, then when you return to the first form the textbox shows the selected value.

gr.z
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 8/21/08 02:11PM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month