簡體   English   中英

來自另一個列表框中使用的一個列表框中的數據

[英]Data from one listbox used in another listbox

我有兩個列表框,一個列表框(lbxTeams)包含橄欖球隊和有關球隊的某些信息(名稱和球員人數),我的第二個列表框(lbxPlayers)包含球員數據(球員名稱,位置和年齡)。

我想要的是:

在從lbxTeams中單擊團隊之一時,我希望所有玩家及其信息都出現在lbxTeams中。

目前,每個列表框(“團隊”和“玩家”)都有一個單獨的類。

我不一定正在學習如何做的代碼,因為我正在大學學習,所以我實際上更喜歡使用解釋或偽代碼而不是有人為我這樣做。

提前致謝!

您如何確定要顯示哪些球員? 你們所有的球員都提及他們的球隊嗎? 如果是這樣,則應該將teamListBox.ItemsSource綁定到球隊列表,並且將teamListBox.SelectedValue綁定到模型中的屬性(例如,“ CurrentTeam”),該屬性將在用戶單擊團隊時生成新的球員列表:

private Team _CurrentTeam;
public Team CurrentTeam
{
    get { return this._CurrentTeam;}
    set {
        this.CurrentTeam = value;
        OnPropertyChanged("CurrentTeam");
        this.CurrentPlayers = this.Players.Where(player => player.Team == value);
    }
}

private IEnumerable<Player> _CurrentPlayers;
public IEnumerable<Player> CurrentPlayers
{
    get { return this.CurrentPlayers; }
    set
    {
        this.CurrentPlayers = value;
        OnPropertyChanged("CurrentPlayers");
    }
}

然后,將playerListBox.ItemSource綁定到CurrentPlayers。

你是這個意思嗎

草案 :

----
(lbxTeams)
- TeamName
- NoOfPlayers

(lbxPlayers)
- PlayerName 
- Position
- Age
----

樣本數據 :

----
(lbxTeams)
----------------------
id (pk) | name
----------------------
t1      | team1
t2      | team2
t3      | team3

(lbxPlayers)
-------------------------------------------------------
name       | position | age | noofplayer | teamid (fk)
-------------------------------------------------------
john       |  left    | 22  | 02         | t2
swan       |  right   | 25  | 09         | t2
charlie    |  mid     | 28  | 05         | t3
hane       |  top     | 27  | 07         | t1
----

設計圖

 ----------
 |lbxTeams|
 ----------
 | team1  | 
 | team2  |--> selected - |
 | team3  |               |
 ----------               v
                    --------------
                    | lbxPlayers |
                    --------------
                    ---------------------------------------------------------
                    | name       | position | age | noofplayer | teamid (fk)
                    ---------------------------------------------------------
                    | john       |  left    | 22  | 02         | t2
                    | swan       |  right   | 25  | 09         | t2
                    ---------------------------------------------------------
----

插圖:

1. you must create 2 table in the databases.
   - table 1 
     - name:lbxTeams
     - fields:
        - id (pk)
        - name
   - table 2
     - name:lbxPlayers
     - fields:
        - name
        - position
        - age
        - noofplayer
        - teamid (fk)

2. insert with the sample data.
3. and then in the query databases, you have to filter the 
   data in the table lbxPlayers is based on table lbxTeams is selected id
4. in the design, if lbxTeams selected 'team1' with id 't2' then just show up the data lbxPlayers with 'teamid' = 't2'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM