简体   繁体   English

在TextBoxes的ListBox中的数据表中显示结果

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

I am doing an assignment on the population of organisms where there are three TextBoxes in my application, that would get the user's input on the "Starting number of organisms" (StartingNumOfOrganismsTextBox), "Average daily increase" (DailyIncreaseTextBox), and "Days to multiply" (NumOfDaysTextBox). 我正在对生物种群进行分配,我的应用程序中有三个文本框,它将获得用户在“生物的起始数量”(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);

When the user inputs int numbers in those textboxes, there should be a Calculate Button, when pressed, it should automatically display the users inputs into a separate ListBox named (PopulationsListBox), as a table of data like this: 当用户在这些文本框中输入int编号时,应该有一个“计算按钮”,当按下该按钮时,它将自动将用户输入显示在名为(PopulationsListBox)的单独的列表框中,作为数据表,如下所示:

For example, if a user enters the following inputs in the TextBoxes mentioned: StartingNumOfOrganismsTextBox: 2 DailyIncreaseTextBox: 30% NumOfDaysTextBox: 5 例如,如果用户在提到的文本框中输入以下输入:StartingNumOfOrganismsTextBox:2 DailyIncreaseTextBox:30%NumOfDaysTextBox:5

Pressing the calculate button, the application should display the following table of data in a ListBox control in two columns. 按下计算按钮,应用程序应在两列的ListBox控件中显示以下数据表。 (Day) column, and (Approximate Population) column. (天)列和(近似人口)列。

Day 1, Approximate Population 2. Day 2, Approximate Population 2.6. 第1天,大约人口2。第2天,大约人口2.6。 Day 3, Approximate Population 3.38. 第3天,大约人口3.38。 Day 4 Approximate Population 4.394. 第4天大约人口4.394。 Day 5, Approximate Population 5.7122. 第5天,人口约为5.7122。

Will someone give me hints on how to take all three of the user inputs, (StartingNumOfOrgranisms, DailyIncrease[%] and then the NumOfDays the organisms will be left to multiply, and display the data of table ina ListBox control? This is very confusing for me, I will be extremely grateful if anyone could help me with this assignment. Thanks. 有人会给我一些提示,如何获取所有三个用户输入((StartingNumOfOrgranisms,DailyIncrease [%],然后是NumOfDays),然后让这些生物进行乘法运算,并在ListBox控件中显示表格的数据吗?这非常令人困惑我,如果有人可以帮助我完成这项任务,我将非常感谢。

Also, I have tried to use the ListView code format to add my data: 另外,我尝试使用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());

But, "SubItems" is not a property ListBoxes use. 但是,“ SubItems”不是ListBoxes使用的属性。 Perhaps someone could suggest trying something similar to that for me? 也许有人会建议为我尝试类似的尝试? I will be thankful. 我会很感激的。

I haven't tested this but you want to do something like this: 我没有测试过,但是您想做这样的事情:

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

Apologies if the sums are all over the place but you can figure those out ;) 抱歉,如果到处都是款项,但您可以弄清楚;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM