Trouble linking parallel array and combo box

时间:2017-04-10 02:15:00

标签: c#

I'm working on a class assignment and I'm trying to learn how to link my parallel arrays to a combo box selection. My textbook doesn't have the information I need and I was hoping someone here could help. My assignment is to build a Payroll System that displays the net pay after taxes. I'm trying to set it up so that a user selects an employee from the combo box and presses a button to calculate the net pay and display the results as well as other employee info that you might see on a paycheck. When I run the program and press the calculate button after making my selection nothing happens. Can anyone tell me why its not working?

Picture of what the user interface looks like

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ZNSPayrollSystem
{
    public partial class ZNSPayrollSystem : Form
    {

        public ZNSPayrollSystem()
        {
            InitializeComponent();


            string[] arr = { "001 Peters", "002 Barnes", "003 Harris" };
            cboEmp.DataSource = arr.ToArray();


        }

        private void btnCalc_Click(object sender, EventArgs e)
        {
            //parallel arrays            
            int[] empID = { 001, 002, 003 };
            string[] empName = { "James Peters", "Sarah Barnes", "Jessica Harris" };
            double[] hrsWorked = { 40, 30, 45 };
            double[] empWage = { 55.50, 65.50, 75.70 };

            //declarations          
            double dblTaxRate = 8.2 / 100;
            double dblNetPay;
            double dblGrossPay;
            double dblTaxWithheld;
            int i = cboEmp.SelectedIndex;

            dblGrossPay = hrsWorked[i] * empWage[i];
            dblTaxWithheld = dblGrossPay * dblTaxRate;
            dblNetPay = dblGrossPay - dblTaxWithheld;

            txtEmpID.Text = empID[i].ToString();
            txtEmpName.Text = empName[i];
            txtHrsWork.Text = hrsWorked[i].ToString();
            txtWage.Text = empWage[i].ToString();
            txtGross.Text = dblGrossPay.ToString();
            txtTax.Text = dblTaxWithheld.ToString();
            txtNetPay.Text = dblNetPay.ToString();

        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            txtEmpID.Text = "";
            txtEmpName.Text = "";
            txtHrsWork.Text = "";
            txtWage.Text = "";
            txtGross.Text = "";
            txtTax.Text = "";
            txtNetPay.Text = "";
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

1 个答案:

答案 0 :(得分:0)

  

单击按钮。然后在属性窗格(右下角)   屏幕默认情况下),点击" Lightning Bolt"图标看到了   活动。向下滚动并找到Click条目并确保它具有   " btnCalc_Click"在那里。 - Idle_Mind

     

@Idle_Mind就是这样!!!我无法相信它就这么简单!?!非常感谢。 - J. Canbeno