App with 2 forms.
Form 1 has a DGV with severaql columns that the users fills in. ONce column is "Store Name" When the user is done they click a button and it is supposed to copy all the rows where the "Store Name" is not blank or 'Walmart' to a textbox on form 2, then Sort the copied list by the "Store Name" so that all the items from one store are grouped together with a blank row in between each grouping and the title of each grouping.
after running several full test runs, I have found that the text box is not quite working the way I want.... Instead of a text box could I copy the rows that have a "store" name filled, to a DGV on form 2 that have all the rows that contain content in the "store" but separated by 1 row and have each section have the store title.
Also when I hit my sort button on form 1 it currently copies to the text box on form 2 and is only supposed to sort the text box list. Currently is does that and it sorts the DGV list on the DGV on form 1. When I entered data I usually enter it by the section of the store so that I get all the items in that section at the same time so I am not running back and forth. So I guess I am saying I want to eliminate the sorting the DGV on form 1. Here is the current code
Form 1 has a DGV with severaql columns that the users fills in. ONce column is "Store Name" When the user is done they click a button and it is supposed to copy all the rows where the "Store Name" is not blank or 'Walmart' to a textbox on form 2, then Sort the copied list by the "Store Name" so that all the items from one store are grouped together with a blank row in between each grouping and the title of each grouping.
after running several full test runs, I have found that the text box is not quite working the way I want.... Instead of a text box could I copy the rows that have a "store" name filled, to a DGV on form 2 that have all the rows that contain content in the "store" but separated by 1 row and have each section have the store title.
Also when I hit my sort button on form 1 it currently copies to the text box on form 2 and is only supposed to sort the text box list. Currently is does that and it sorts the DGV list on the DGV on form 1. When I entered data I usually enter it by the section of the store so that I get all the items in that section at the same time so I am not running back and forth. So I guess I am saying I want to eliminate the sorting the DGV on form 1. Here is the current code
Code:
Private Sub btnSortLists_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSortLists.Click
ShoppingListView.Sort(ShoppingListView.Columns(3), System.ComponentModel.ListSortDirection.Ascending) 'simply sorts by store name
PriceMatchStore.txtStoreList.Text = ""
For i = 0 To ShoppingListView.Rows.Count - 2
If ShoppingListView.Rows(i).Cells(3).Value.ToString <> "Walmart" AndAlso ShoppingListView.Rows(i).Cells(3).Value.ToString <> "" Then ' add this line
'for editable dgv but you do need to ensure that there is only one blank line and it's at the end!!!
If i = 0 OrElse Not ShoppingListView.Rows(i).Cells(3).Value.Equals(ShoppingListView.Rows(i - 1).Cells(3).Value) Then
NewHeading(ShoppingListView.Rows(i).Cells(3).Value.ToString, PriceMatchStore.txtStoreList) ' change of store
End If
AddLine(ShoppingListView.Rows(i), PriceMatchStore.txtStoreList)
End If ' add this line
Next
PriceMatchStore.ShowDialog()
End Sub
Private Sub AddLine(ByVal dgr As DataGridViewRow, ByVal tb As TextBox)
For i = 1 To 6
If i <> 3 Then ' no point showing the store a second time
Try 'prevent unhandled null exceptions from blank cells
tb.AppendText(dgr.Cells(i).Value.ToString & vbTab & vbTab)
Catch ex As Exception
tb.AppendText(vbTab)
End Try
End If
Next
tb.AppendText(vbCrLf)
End Sub