Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42220

TExtbox List Sorted from Data Grid View Not working properly

$
0
0
I have a DataGridView that when i click a button it sorts it by store name into a textbox on a dialog form, but for the life of my i can figure out why it is not displaying correctly

This is how it is entered into the DataGridView


Attachment 94893

So that I am trying to achieve is for it to be sorted BY store and grouped together by store so you only see the store name once and all the items for that sotre underneath the name (Which it does), but I want to exclude anything that has the store listed as walmart, and if there is not a store listed I do not want it in here. Also as you can see below the items actually show up in the Brand Column, Brands dont show up, The store is listed again and the price is under the coupon column, size is off by itself and there is on coupons at all.

This is how it is displayed:


Attachment 94891
Here is My code
Code:

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
            '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)
        Next
        PriceMatchStore.ShowDialog()
    End Sub



    Private Sub NewHeading(ByVal s As String, ByVal tb As TextBox)
        tb.AppendText(vbCrLf & s.ToUpper & vbCrLf & New String("="c, s.Length) & vbCrLf)
        tb.AppendText("Item" & vbTab & "Brand" & vbTab & "Price" & vbTab & "QTY" & vbTab & "Coupon" & vbCrLf)
    End Sub

    Private Sub AddLine(ByVal dgr As DataGridViewRow, ByVal tb As TextBox)
        For i = 0 To 5
            If i <> 2 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)
                Catch ex As Exception
                    tb.AppendText(vbTab)
                End Try
            End If
        Next
        tb.AppendText(vbCrLf)
    End Sub

:eek2:
Attached Images
   

Viewing all articles
Browse latest Browse all 42220

Trending Articles