DataGrid Again n Again

rex028

Well-known member
Joined
Nov 18, 2004
Messages
50
Programming Experience
Beginner
the case is:
i'm doing a purchase order ...
with serval text box ... i search by PO ID ...
then Item_No, Item_Quantity will show on the datagrid...
Well, when press the search again ...
the datagrid will get the same data again !
that's mean it displayed a duplicated data !!

VB.NET:
   Private Sub GetPoDetails()
		
		objDS.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"))
					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
 
another question ...
a Purchase Order Contains Serval Items ... isn't it !!
then i wanna Update/Modify it ... i search the PO ID ...
Record display on the Datagrid ... well ...
there are lot of items in One PO .. right !!
what if i just wanna modify one of item ...

what i want to do is .. i double click on one datagrid row ...
then this row of record will display in the specific Textbox !!

But the problem IS ... i know nothing about the datagrid command !!
i'm stuck in the datagrid for almost two months ...

Please Help me OUT !!! i'm so frustrated !!!
 
as far as the duplicate records... change
VB.NET:
dgPOrderItems.DataSource = objDS.Tables(0).DefaultView

to
VB.NET:
 dgPOrderItems.DataSource =nothing 
dgPOrderItems.DataSource.refresh
dgPOrderItems.DataSource = objDS.Tables(0).DefaultView


for the current row values...
VB.NET:
dgPOrderItems.CurrentRowIndex

double click...
VB.NET:
PrivateSub dgPOrderItems_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgPOrderItems.DoubleClick


hope this was helpful
 
VB.NET:
dgPOrderItems.DataSource =nothing 
dgPOrderItems.DataSource.refresh
dgPOrderItems.DataSource = objDS.Tables(0).DefaultView

not work ... nothing display on the datagrid ...
 
my fault, you need to refresh the grid again at the end. Sorry about that.:eek:

also, if you're using mapping ( if you specified the "TableStyles" for the grid), you would do the following:
VB.NET:
[left]dgPOrderItems.DataSource =nothing[/left]
[left]dgPOrderItems.DataSource.refresh[/left]
[left]dgPOrderItems.DataSource = objDS.Tables(0).DefaultView[/left]
[left]<Table Style Name Here>.MappingName = objDS.Tables(0).TableName[/left]
[left]dgPOrderItems.Refresh()[/left]
if you're not using table styles, use the above code but omit the table style line.

that should do the trick
 
i've tried it ... but still not work

i tried this ... but it display all stuff i have selected ...
tablestyle gone ...
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.DataSource = Nothing
				ts1.MappingName = objDS.Tables(0).ToString
				dgPOrderItems.DataSource = objDS.Tables(0).DefaultView
				ts1.MappingName = objDS.Tables(0).ToString
				dgPOrderItems.Refresh()
if add the tablestyle back ...
the data still duplicate when i click again ....
VB.NET:
 dgPOrderItems.DataSource = Nothing
				ts1.MappingName = objDS.Tables(0).ToString
				dgPOrderItems.TableStyles.Add(ts1)
				dgPOrderItems.DataSource = objDS.Tables(0).DefaultView
				ts1.MappingName = objDS.Tables(0).ToString
				dgPOrderItems.Refresh()
 
Back
Top