A two list box selector with add and remove RRS feed

  • Question

  • I would like to create something like in Lightswitch.  I have 3 tables.  Players, Match and MatchPlayers.  The MatchPlayers table has three fields: ID, Player (Relationship), Match (Relationship).   The left list contains Players.  The right list is attached to the MatchPlayers list.  When a player is selected and the Add button it will add the player to the MatchPlayers table and then filter it out of the players table so it is not displayed until a new Match is created...  I know that i will have left so many details.  If i can get pointed in the right direction it would be appreciated...



    Tuesday, March 31, 2015 8:30 AM

All replies

  • Hello

    I dont see this as too complicated a task.

    Personally, I would set up a query on the Players table and another on the MatchPlayers table. Each will be based on the selected Match (MatchId).

    Then I would go into the _PreProcess of the query and just create a list of id's that were in that match already and then make sure that the Id in the list is not one of the players ones. On the adding and removing you will have to refresh the dataset but again this is one line of code.

    You will have to do some set up to make sure that there is a match selected in the first instance and do a bit more troubleshooting on it but here is a quick part that I have been able to rustle up. The first screenshot shows that players 1 and 2 have been added onto a match, the second shows the next match with all players back. All is based on the Match Id which is highlighed at the top of the screen and the _PreProcess Code in the query is below.

            partial void PlayersCat_PreprocessQuery(int? Id, int? MatchId, ref IQueryable<Players> query)
                var myList = (from MatchPlayers items in this.MatchPlayersSet where items.Match.Id == MatchId select items.Players.Id).ToList();
                query = from items in query where !myList.Contains(items.Id) select items;

    Two players selected

    next match all players are back

    Hope this helps

    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    • Proposed as answer by Otis Ranger Tuesday, April 14, 2015 3:39 PM
    Tuesday, April 14, 2015 3:39 PM