Compare each item in grid selected items

Larry Brister
Larry Brister used Ask the Experts™
on
In my attached code I want to look at each afsSourceDetail string coming in

If it doesn't = the same thing every time...exit the sub.

afs1
afs1
afs1

works

afs1
afs1
afs2
afs1

Exits sub.
For Each item As GridDataItem In grdAvailableForSale.SelectedItems
                    If item("afsSourceDetail").Text <> (previous afssourcedetail) Then
                        Exit Sub
                    Else

                    End If
                Next

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dim Prev as String = grdAvailableForSale.SelectedItems.First.Text
For Each item As GridDataItem In grdAvailableForSale.SelectedItems
                    If item("afsSourceDetail").Text <> prev Then
                        Exit Sub
                    Else

                    End If
                Next
Larry Bristersr. Developer

Author

Commented:
lludden:
This is a Telerik RadGrid which doesn't have a ".First." method
.First should be a LINQ extension method.  If you don't have it, set it to the first element in the list

Dim Prev as String = ""
For Each item As GridDataItem In grdAvailableForSale.SelectedItems
                    if Prev = "" then
                         Prev = item("afssourcedetail").Text
                    end if
                    If item("afsSourceDetail").Text <> prev Then
                        Exit Sub
                    Else

                    End If
                Next
Larry Bristersr. Developer

Author

Commented:
Perfect...thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial