簡體   English   中英

在TextBoxes的ListBox中的數據表中顯示結果

[英]Displaying results in table of data in a ListBox from TextBoxes

我正在對生物種群進行分配,我的應用程序中有三個文本框,它將獲得用戶在“生物的起始數量”(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);

當用戶在這些文本框中輸入int編號時,應該有一個“計算按鈕”,當按下該按鈕時,它將自動將用戶輸入顯示在名為(PopulationsListBox)的單獨的列表框中,作為數據表,如下所示:

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

按下計算按鈕,應用程序應在兩列的ListBox控件中顯示以下數據表。 (天)列和(近似人口)列。

第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使用的屬性。 也許有人會建議為我嘗試類似的嘗試? 我會很感激的。

我沒有測試過,但是您想做這樣的事情:

        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));
        }

抱歉,如果到處都是款項,但您可以弄清楚;)

暫無
暫無

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

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