7 Replies - 2143 Views - Last Post: 05 May 2009 - 01:21 AM Rate Topic: -----

#1 jeff87  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 85
  • Joined: 17-March 09

Passing data to another form

Posted 28 April 2009 - 10:34 PM

hi all,currently i got 2 forms.there are 2 buttons in the 1st form....and what i wan is,when a user click button 1,then will show form 2 will related data,click button 2 will show related data which is different with form 1.so far wat i get is,i oni manage to make when a user click button 1,then show form2 n in d form 2 there is another button to click n get d data...which mean i nid 2 create more forms...erm...u can say that i would like to make the form 2 to become a template...and send data into it...tats all hope can get sum helps here!thx!!

cheers,
regards.


this is d form1 button
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
   form2.show()
	End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
   form3.show()
	End Sub



this is d form2 n 3
 Private Sub form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
	 
		con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=test.mdb"
		con.Open()

		sql = "SELECT * FROM Agent"
		sql2 = "SELECT * FROM PO"

		da = New OleDb.OleDbDataAdapter(sql, con)
		da1 = New OleDb.OleDbDataAdapter(sql2, con)

		da.Fill(ds, "KDE")
		da1.Fill(ds2, "KDE1")

		con.Close()

		MaxRows1 = ds.Tables("KDE").Rows.Count
		MaxRows2 = ds2.Tables("KDE1").Rows.Count
		inc = 0

		Getdata()

		TextBox1.Enabled = "false"
		TextBox2.Enabled = "false"
		TextBox3.Enabled = "False"
		TextBox4.Enabled = "false"

		'DataGridView1.Visible = "false"


	End Sub
	Sub Getdata()
		TextBox1.Text = ds.Tables("KDE").Rows(0).Item(0)
		TextBox2.Text = ds.Tables("KDE").Rows(0).Item(1)
		TextBox3.Text = ds.Tables("KDE").Rows(0).Item(2)
		TextBox4.Text = ds.Tables("KDE").Rows(0).Item(3)
	End Sub



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

	  
		'For c1 = 0 To (MaxRows1 - 1) 'notice starts at zero and to one less than the number of rows in the table 
		'If CStr(ds2.Tables("KDE1").Rows(c1).Item(1)) = Cust Then
		'CustomerFound = True
		'total = +ds2.Tables("KDE1").Rows(c1).Item(10)

		' End If
		' Next
		' TextBox5.Text = total





		Dim testdt As testDataSet.PODataTable




		With Me.DataGridView1
			.SelectionMode = DataGridViewSelectionMode.FullRowSelect
			.MultiSelect = False
		End With
		Dim testda As New testDataSetTableAdapters.POTableAdapter
		Dim c1 As Integer					   'counter for loop
		Dim Cust As String
		Dim CustomerFound As Boolean = False
		Dim total As Integer
		Dim total1 As Integer
		Dim total2 As Integer
		Dim total3 As Integer
		Dim total4 As Integer
		Dim total5 As Integer
		Dim total6 As Integer
		Cust = TextBox1.Text


		testdt = testda.GetData

		DataGridView1.DataSource = testdt
		If TextBox1.Text = "" Then
			MsgBox("Please Insert A Member ID")
		Else
			testdt.DefaultView.RowFilter = "Agent= '" & TextBox1.Text & "'"


			For c1 = 0 To (MaxRows2 - 1) 'notice starts at zero and to one less than the number of rows in the table 
				If CStr(ds2.Tables("KDE1").Rows(c1).Item(1)) = Cust Then
					CustomerFound = True
					total += ds2.Tables("KDE1").Rows(c1).Item(10)
					total1 += ds2.Tables("KDE1").Rows(c1).Item(17)
					total2 += ds2.Tables("KDE1").Rows(c1).Item(24)
					total3 += ds2.Tables("KDE1").Rows(c1).Item(31)
					total4 += ds2.Tables("KDE1").Rows(c1).Item(38)
					total5 += ds2.Tables("KDE1").Rows(c1).Item(45)

				End If
			Next
			TextBox5.Text = total
			TextBox6.Text = total1
			TextBox7.Text = total2
			TextBox8.Text = total3
			TextBox9.Text = total4
			TextBox10.Text = total5
			total6 = +TextBox5.Text + TextBox6.Text + TextBox7.Text + TextBox8.Text + TextBox9.Text + TextBox10.Text
			TextBox11.Text = total
		End If
	End Sub


i just wana make like i click button1 in form1,it will pop out form2 wit related data..thx!

Is This A Good Question/Topic? 0
  • +

Replies To: Passing data to another form

#2 MajorWalrus  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 115
  • Joined: 22-April 09

Re: Passing data to another form

Posted 29 April 2009 - 11:16 AM

Phew.

Okay, I'm having trouble understanding you, so let me parse what I think is going on and you can tell me if that's right.

You've got a form, its has a button on it. You click the button and another form opens with data that's pulled from your database.

So far, so good?

Now, judging by your code, nothing is happening. Except the form opening. Here are some of the potential causes:

With Me.DataGridView1


This is inside the sub for the button. Does a command button object have a member that's called DataGridView? If not, its trying to reference a method or property that doesn't exisit.

testdt = testda.GetData


You've declared testdt as a PODataTable, but not testda. I'd bet this isn't working because you just got the two reversed. Maybe. But, what is GetData? Are you calling the sub GetData()?

[Edit:] Okay, I found the declaration. But this just underscores the difficulty one has in reading the code the way you're written it. (See below.)

Those two just jumped out at me. The bigger problem that I see is the naming of objects and variables. Its very hard to follow your code because nothing has a unique name. Try renaming some of the fields, for example, it will help you follow your thoughts, and help us, too.

All this said, I'm not really sure what problem you're expirencing. Are you getting any errors? Does it compile? Give us a sense of the problem so we know where you're getting stuck.

Lastly, given that English is likely a second language for you, perhaps you could attach some screenshots for us to look at. That might give us a sense of what you're doing.

Good luck!
Was This Post Helpful? 0
  • +
  • -

#3 jeff87  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 85
  • Joined: 17-March 09

Re: Passing data to another form

Posted 29 April 2009 - 07:45 PM

sry for my bad english....actually it does not giv me any error.it works fine n work as wat i expected.....but then wat i wan is,a simply way...i will giv another example...


tis is wat i had now..
form1 has got 2 buttons,when i click button 1,form 2 shows up....in d form2 got a datagrid n few textbox n a button..n d datagridview got a filter function.so when form2 shows up,i click d button n d data will show...

so d another button in form1 doing same thing....but thn its too messy coz i nid 2 create more form which is form 3 to get data.

is it possible tat i make form2 as a template,n when i click button1 in form will show form2 n dun nid any button in form2? and when i click button2 in form 1,it will show form 2 oso wit related data which mean i just wan 2 forms.. tats all...

can u understand me?
sry for my bad expression...
:ph34r:

This post has been edited by jeff87: 29 April 2009 - 08:19 PM

Was This Post Helpful? 0
  • +
  • -

#4 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 945
  • View blog
  • Posts: 6,342
  • Joined: 18-October 08

Re: Passing data to another form

Posted 29 April 2009 - 09:59 PM

Your best bet would be to create an XML document before you create the other form and when you click the button on the other form read in the XML document.
Was This Post Helpful? 0
  • +
  • -

#5 jeff87  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 85
  • Joined: 17-March 09

Re: Passing data to another form

Posted 29 April 2009 - 11:14 PM

but i noe nothing about XML....
Was This Post Helpful? 0
  • +
  • -

#6 MajorWalrus  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 115
  • Joined: 22-April 09

Re: Passing data to another form

Posted 30 April 2009 - 12:28 PM

No need to apologize, Jeff.

What about using two DataGridViews? Add them both to form 2 and set one to invisible. When you click on button 1 it would display the form and datagridview1. When you click button 2 to would display the form with datagridview1 hidden and datagridview2 visible.
Something like this:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
   form2.show()
   form2.datagridview1.visible = true
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
   form2.show()
   form2.datagridview2.visible = true
End Sub


Just set the visible property to "false" for both when you build the form.

This post has been edited by MajorWalrus: 01 May 2009 - 05:16 AM

Was This Post Helpful? 0
  • +
  • -

#7 jeff87  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 85
  • Joined: 17-March 09

Re: Passing data to another form

Posted 04 May 2009 - 06:07 PM

View PostMajorWalrus, on 30 Apr, 2009 - 11:28 AM, said:

No need to apologize, Jeff.

What about using two DataGridViews? Add them both to form 2 and set one to invisible. When you click on button 1 it would display the form and datagridview1. When you click button 2 to would display the form with datagridview1 hidden and datagridview2 visible.
Something like this:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
   form2.show()
   form2.datagridview1.visible = true
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
   form2.show()
   form2.datagridview2.visible = true
End Sub




Just set the visible property to "false" for both when you build the form.

thx man,its a good idea,but i'd found out a solution tats fit me! :D i pass d data to another form just by adding few code

form2.textbox1.text=textbox1.text
anyway!thx for ur help!actually i still got alot of question.do i nid 2 open new topic or i can continue here?

cheers,
regards
Was This Post Helpful? 0
  • +
  • -

#8 jens  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 67
  • View blog
  • Posts: 430
  • Joined: 09-May 08

Re: Passing data to another form

Posted 05 May 2009 - 01:21 AM

Here's a nice way of doing it. /Jens
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1