DataView Find Problem!!

Hi,

I have a dataview with a football league table, already sorted showing the position of each team in the league. I want to find a specific team in the league table to find out which row they are in within my dataview. I'm trying the 'Find' method but keep coming up the a "Expecting 3 value(s) for the key being indexed, but received 1 value(s)" error. I have set a Primary Key on one value (I have a column called 'Pos' relating to a numeric position in the league), but can't get it to work - I want to output the position of my specific team (MySelectedTeam) into the integer value 'x'. Here is the code:

Dim DataView As Data.DataView
DataView = dsMonth.Tables(0).DefaultView
             
dsMonth.Tables(0).PrimaryKey = New Data.DataColumn() {dsMonth.Tables(0).Column("pos")}

DataView.Sort = "[points] DESC,[totalgd] desc,[teamname]"
       
Dim x As Integer = DataView.Find("MySelectedTeam")
ewangardnerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jatinderalaghCommented:
Looks to me

DataView.Find finds a row in the DataView by the specified sort key value.
You are using 3 keys to sort but one for selecting it

jatinder
0
ewangardnerAuthor Commented:
Ok, that makes sense, but I need to sort by three keys but can only search one (Teamname) because I won't know the other two values i.e. Points and Goal difference. How would I do that?
0
SystemExpertCommented:
Hi
It would often be useful to be able to sort by more than one column in a DataGrid. .Net has no built-in way to sort by multiple columns, but this article shows one way that some extra code can make this "multi-sorting" possible.

This is what you want.

http://authors.aspalliance.com/olson/code/multisort/multisort.aspx?c=3&d=0&ls=2:0

Thanks
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

SystemExpertCommented:
Hi,

This is source code link

http://aspalliance.com/5

previous was for live DEMO

Thanks
0
jatinderalaghCommented:
Try this.

step1. Sort the dataview only by team name.
step2. Now find the rows by teamname using FindRows method.
step3. Now with in these Rows you can again provide your rest of filters and select the first row.

That will provide you desired result.


Jatinder
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ewangardnerAuthor Commented:
Thanks for all your help guys. Managed to do it after ALL DAY trying. Here's how.

jatinderalagh was correct initially because I had set three keys and then only tried to perform the find on one category. This is fine, but I need to filter by three for the league to be in the correct order.

So, I can use the Dataview.Find on one category i.e. teamname, the one I know, but I can't use find when using all three category sorts because Find requires that you specify exactly what you're looking for for all three. I can't know the other two categories (points and goal difference) and thus I can't use Find.

However, jatinderalagh's second post gave me the inspiration for the solution. I can perform the Find on teamname alone, find out what the values are for points and goal difference, then sort and find using all three categories, inputting the values I found, to discover the row index of my selected team as it would appear in the correct league order.

Confusing I know, but here is my final code which should clear up the confusion.


        'Sort by teamname alone and find my selected team

        DataView.Sort = "teamname"
        Dim p = DataView.Find("Thurrock")
       
        'This is the row where MySelectedTeam appears at the moment...

        temprow = DataView(p).Row
       
        '...and I can use this row index go get the other values I need

        temp_points = temprow("points")
        temp_gd = temprow("totalgd")
       
        'Now I can sort with all three values to give me the correct league order

        DataView.Sort = "points desc, totalgd desc, teamname"
       
        'I now assign all the desired Find search values (including the ones I didn't know)
        'into the vals array

        Dim vals(2) As Object
        vals(0) = temp_points
        vals(1) = temp_gd
        vals(2) = "Thurrock"
       
        'Here I perform the Find, and I get the row index I need for my team

        Dim x As Integer = DataView.Find(vals)

jatinderalagh provided the inspiration, I'm going to award the points to him, but thanks for the other suggestions.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.