2013-03-30 99 views
0

我正在做有關生物種羣的任務,其中有三個文本框在我的應用程序中,這將獲得用戶對「起始生物體數量」(StartingNumOfOrganismsTextBox)的輸入。 ,「每日平均增長量」(DailyIncreaseTextBox)和「乘法日數」(NumOfDaysTextBox)。在文本框中顯示列表框中的數據結果

 int NumOfOrganisms = 0, DailyIncrease = 0, NumOfDays = 1; 

     StartingNumOfOrganisms = int.Parse(StartingNumOfOrganismsTextBox.Text); 
     DailyIncrease = int.Parse(DailyIncreaseTextBox.Text); 
     NumOfDays = int.Parse(NumOfDaysTextBox.Text); 

當用戶輸入在那些文本框詮釋號碼,應該有一個計算按鈕,當被按下時,它會自動顯示用戶輸入到名爲(PopulationsListBox)一個單獨的列表框,因爲這樣的數據表:

例如,如果用戶輸入在文本框以下輸入提到: StartingNumOfOrganismsTextBox:2 DailyIncreaseTextBox:30%NumOfDaysTextBox:5

按計算按鈕時,應用程序應顯示數據的下表中一個ListBox控件在tw中o專欄。 (日)欄和(大致人口)欄。

第1天,大概人口2.第2天,大約人口2.6。第3天,大約人口3.38。第4天大約人口4.394。第5天,大約人口5.7122。

有人會告訴我如何將所有三個用戶輸入(StartingNumOfOrgranisms,DailyIncrease [%],然後是NumOfDays有機體將剩下的乘法,並在ListBox控件中顯示錶的數據嗎? 。對我來說是非常混亂,我將非常感激,如果有人可以幫助我這個任務感謝

另外,我曾嘗試使用ListView控件的代碼格式,添加我的數據:

 PopulationsListBox.Items.Add("1"); 
     PopulationsListBox.Items[0].SubItems.Add(StartingNumOfOrganisms.ToString()); 
     for (int i=2;i<=NumOfDays;++i) 
     { 
      PopulationsListBox.Items.Add(i.ToString()); 
      PopulationsListBox.Items[PopulationsListBox.Items.Count-1].SubItems.Add((StartingNumOfOrganisms+StartingNumOfOrganisms*DailyIncrease).ToString()); 

但,「SubItems」不是ListBoxes使用的屬性,也許有人可能會建議嘗試類似於我的東西?我會我很感激。

+0

如果每個單元由多個數據,你確定你想要一個ListBox而不是ListView嗎? – Nolonar

+0

根據規則,我不能使用ListView來放入我的數據表。它必須是一個ListBox。 :(我曾嘗試在ListView格式中使用它,但不幸的是,當我將數據添加爲「SubItem」時顯然ListBoxes沒有SubItem屬性 – Cindy

+0

「根據規則」 - 我們是否幫助您完成家庭作業? – LosManos

回答

0

我沒有測試過這一點,但你想要做這樣的事情:

 listbox.Items.Add("Day 1, Approximate Population:" + txtStartingNumberOfOrganisms.Text); 
     int ApproximatePopulation = Convert.ToInt16(txtStartingNumberOfOrganisms.Text);    

     for (int i = 2; i <= numOfDays; i++) 
     { 
      ApproximatePopulation = ApproximatePopulation + ((ApproximatePopulation * Convert.ToDouble(txtDailyIncrease.text))/100); 
      listbox.Items.Add("Day " + Convert.ToString(i) + ", Approximate Population:" + Convert.ToString(ApproximatePopulation)); 
     } 

道歉,如果總和是所有的地方,但你可以計算出那些;)

+0

做了一些編輯,因爲我沒有轉換文本框的數據 –

+0

謝謝史蒂芬。:)我已經使用你的代碼計算出了我的項目。 – Cindy

相關問題