How can i pass Data from one DataGrid to another ?

rex028

Well-known member
Joined
Nov 18, 2004
Messages
50
Programming Experience
Beginner
i'm using Two Windows Form ... for example Form1 and Form2

i have DataGrid in each Form

then i wanna pass the Data to Form1's Datagrid from Form2's Datagrid ....

how can i do it ????

can you give me some hints ??

please help !!!
 
make a global dataset by putting this code at the top of your form below public class form1:
public shared dataset as new dataset

Then read the data into it, then in form 1 :
datagrid.source=dataset

In form 2:
datagrid2.source=form1.dataset
 
For example:

in datagrid 2 : there are Four rows ...
i select one row .. then i want to add this row into datagrid 1

is it the same as you teach me ??
 
Hmm I see, well you could do it like that but have 2 datasets. 1 shared public and 1 private. Dagagrid2 uses private, Datagrid1 uses public. when user clicks the button you just add the data from the private dataset to the public.
 
sorry could you show me how to coding look like ?

becoz i'm really worse in VB.NET !!

PLEASE HELP ME !!
 
form 1 :
public shared DS1 as dataset
datagrid1.datasource = DS1


Form 2 :
onload...
Dim DS2 as dataset
...read data into dataset...
Gatagrid2.datasource = DS2

onclick..
dataset1.rows.add (dataset2.rows(gatagrid2.currentrowindex))
 
VB.NET:
  dataset1.rows.add (dataset2.rows(gatagrid2.currentrowindex))

it says "rows" is not a member of "System.Data.Dataset"
 
Sorry missed tables in there :
dataset1.tables(0).rows.add (dataset2.rows(gatagrid2.currentrowindex))
 
i still not really understand how it works ...

may be i describe my situation more specific ...

i have a Purchase Order ... with One DataGrid contain PO
then
i press a search Items button a ItemSearch windows from pop up ...
i do item search there ... record display in a datagrid there ..
when i double click it .. the selected item record will pass to Purchase Order's datagrid ..
 
sorry ...
my problem is i still couldn't pass the Data from ItemSearch to PurchaseOrder

actually .. there are a problem in PurchaseOrder too ...

that's when i create a new PurchaseOrder ... i have to hold the new PO in Datagrid until all purchase items are add into the PO ... right !!

so how can i hold them in the datagrid ...

and

i follow the solution you teach me ...

i get an error that is DS1 can not be declare even i set DS1 is public shared !!
 
So it's your dataset your having problems with then, not the data...

Public shared? is the dataset on another form? If so you'll need to call the form then the dataset eg form1.ds1

Did you remember the new when diming your dataset? ie dim ds1 as new dataset
 
as you taught me b4 ..
i can't show different data in two datagrids in same windows form now !!
i have two DataGrid : dgItemsDetails , dgPO

now ..
dgItemsDetails on left hand side and dgPO on right hand side...
there are two buttons between them..
what i want to do is ... i select a row of itemdetails and press "add" ...
it will add to the dgPO ...

i'm using one Dataset only ...
my code like this ..
VB.NET:
  Private Sub GetPoDetails()
		objDS.Tables.Clear()
		objDS = objUser.Search_tblUser(" SELECT  p.* , s.Supplier_ID, s.Supplier_Name FROM tbl_SUPPLIER s, tbl_PURCHASE p where (p.PO_ID = '" & txtPOID.Text & "') and (p.Supplier_ID = s.Supplier_ID ) ")
		Try
			If objDS.Tables(0).Rows.Count <= 0 Then
				MsgBox("Record Not Found")
			End If
			If objDS.Tables(0).Rows.Count > 0 Then
				ts1.MappingName = objDS.Tables(0).ToString
				With tc1
					.HeaderText = "Item No."
					.MappingName = "Item_No"
					.Width = 60
				End With
				With tc2
					.HeaderText = "Item Price"
					.MappingName = "Item_Price"
					.Width = 60
				End With
				With tc3
					.HeaderText = "Item Quantity"
					.MappingName = "Item_Quantity"
					.Width = 80
				End With
				ts1.GridColumnStyles.Add(tc1)
				ts1.GridColumnStyles.Add(tc2)
				ts1.GridColumnStyles.Add(tc3)
				dgPOrderItems.TableStyles.Add(ts1)
				dgPOrderItems.DataSource = objDS.Tables(0).DefaultView

				With objDS.Tables(0)
					txtPOBranchID.Text = objFormat.FormatString(.Rows(0).Item("Branch_ID"))
					txtPOID.Text = objFormat.FormatString(.Rows(0).Item("PO_ID"))
					txtPOItemNo.Text = objFormat.FormatString(.Rows(0).Item("Item_No"))
					txtPOItemQua.Text = objFormat.FormatString(.Rows(0).Item("Item_Quantity"))
					txtPOItemPrice.Text = objFormat.FormatString(.Rows(0).Item("Item_Price"))
					txtPODay.Text = objFormat.FormatString(.Rows(0).Item("Order_Date").Day.ToString)
					txtPOMonth.Text = objFormat.FormatString(.Rows(0).Item("Order_Date").Month.ToString)
					txtPOYear.Text = objFormat.FormatString(.Rows(0).Item("Order_Date").Year.ToString)
					txtPOModifitedDate.Text = objFormat.FormatString(.Rows(0).Item("Modified_Date"))
					txtPOModifitedBy.Text = objFormat.FormatString(.Rows(0).Item("Modified_By"))
					txtPOSupplierID.Text = objFormat.FormatString(.Rows(0).Item("s.Supplier_ID"))
					txtPOsuppliername.Text = objFormat.FormatString(.Rows(0).Item("Supplier_Name"))

				End With
			End If
		Catch ex As Exception
		End Try
	End Sub

VB.NET:
 Private Sub GetItemDetails()
		objDS.Tables.Clear()
		objDS = objUser.Search_tblUser("Select * from tbl_ITEM where Item_Type = '" & cboPOItemType.Text & "'")
		Try
			dgPOproductinfo.DataSource = objDS.Tables(0)
		Catch ex As Exception
		End Try
	End Sub
 
Back
Top