Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6133009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:10:21+00:00 2026-05-23T17:10:21+00:00

I am learning C# and am making a custom Payroll application. I have a

  • 0

I am learning C# and am making a custom Payroll application. I have a form for employer periods that allows a user to enter/edit or delete one payroll period at a time, i.e, there can only be one record in the database at a given time.

I have a method on form load that will retrieve all needed fields if a payroll period exists.

Code:

private void PayrollPeriodForm_Load(object sender, EventArgs e)
{
    dateTimePicker2.Value = dateTimePicker2.Value.AddYears(1).AddDays(-1);

    // Get service instance
    var employerPeriodService = Program.Kernel.Get<IEmployerPeriodService>();

    //Query database
    var employerPeriods = employerPeriodService.GetAllEmployerPeriods();                                      

    if (employerPeriods.Any(x => x != null))
    {
        var employerPeriod = employerPeriods.First();

        txt_tax_year.Text = employerPeriod.U_Tax_year.ToString();
        lbl_code.Text = employerPeriod.Code;
        cb_number_hours.Text = employerPeriod.U_Day_hrs.ToString();
        cb_number_days_week.Text = employerPeriod.U_Week_days.ToString();
        cb_number_days_month.Text = employerPeriod.U_Month_days.ToString();
        cb_number_days_fortnight.Text = employerPeriod.U_Fortnight_days.ToString();
        txt_number_hours_week.Text = employerPeriod.U_Week_hrs.ToString();
        txt_number_hours_fortnight.Text = employerPeriod.U_Fortnight_hrs.ToString();
        txt_number_hours_month.Text = employerPeriod.U_Month_hrs.ToString();
        cb_avg_weeks_month.Text = employerPeriod.U_Weeks_in_month.ToString();
        cb_avg_fortnights_month.Text = employerPeriod.U_No_of_Fortnights.ToString();
        dateTimePicker1.Text = employerPeriod.U_Starting_period.ToString();
        dateTimePicker2.Text = employerPeriod.U_Ending_period.ToString();

        txt_tax_year.Enabled = false;
        dateTimePicker1.Enabled = false;
        dateTimePicker2.Enabled = false;
        btn_add.Enabled = false;
        btn_update.Enabled = true;
        btn_delete.Enabled = true;
        btn_update.Visible = true;
        btn_delete.Visible = true;
        btn_add.Visible = false;

        // Store SAP code
        SAPCodePeriod = employerPeriod.Code;
    }
    else
    {
        //clear textfields after input
        cb_number_hours.SelectedIndex = 0;
        cb_number_days_week.SelectedIndex = 0;
        txt_number_hours_week.Text = "";
        cb_number_days_month.SelectedIndex = 0;
        txt_number_hours_month.Text = "";
        cb_number_days_fortnight.SelectedIndex = 0;
        txt_number_hours_fortnight.Text = "";
        cb_avg_weeks_month.Text = null;
        cb_avg_fortnights_month.Text = null;
        lbl_code.Text = "";

        txt_tax_year.Enabled = true;
        dateTimePicker1.Enabled = true;
        dateTimePicker2.Enabled = true;
        btn_add.Enabled = true;
        btn_update.Enabled = false;
        btn_delete.Enabled = false;
        btn_add.Visible = true;
        btn_update.Visible = false;
        btn_delete.Visible = false;
    }
}

I have two selectd index changed events for 2 of my comboboxes so far:

private void cb_number_hours_SelectedIndexChanged(object sender, EventArgs e)
{
    // calculate hours/week
    var hoursWeek = (int.Parse(cb_number_hours.Text)) * (int.Parse(cb_number_days_week.Text));

    txt_number_hours_week.Text = hoursWeek.ToString();
}

private void cb_number_days_week_SelectedIndexChanged(object sender, EventArgs e)
{
    // calculate hours/week
    var hoursWeek = (int.Parse(cb_number_hours.Text)) * int.Parse(cb_number_days_week.Text);

    txt_number_hours_week.Text = hoursWeek.ToString();
}

My Problem:
Before I had any of the SelectedIndexChanged methods, All the values from the database were showing in their appropriate textboxes and comboboxes.

However after adding the cb_number_hours_SelectedIndexChanged method, all textbox and combobox values from the DB after cb_number_hours.Text stopped showing. This has resulted in The calculation in the methods not to work as (int.Parse(cb_number_days_week.Text)) is seen as null.

How do I fix this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:10:22+00:00Added an answer on May 23, 2026 at 5:10 pm

    In your cb_number_hours_SelectedIndexChanged event handler, try adding a check for a valid value before the rest of your code, like this (untested):

    int hours;
    int days;
    
    if (Int32.TryParse(cb_number_hours.Text, out hours) && Int32.TryParse(cb_number_days_week.Text, out days))
    {
       var hoursWeek = hours * days;
       txt_number_hours_week.Text = hoursWeek.ToString();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am learning the C# programming language and am making a payroll application add-on
I am learning the C# programming language and am making a payroll application add-on
I am learning the C# programming language and am making a payroll application add-on
I have a noob question but he, i'm learning :-) I'm making a form
I have started learning titanium framework.I was making application into iphone.I have made application
I'm making an MMO which will have a 2d world. (This is a learning
I am making a simple CMS just for learning purposes and I have a
Im am learning C# and am making a Payroll Add-On for SAP Business One.
I am learning the C# programming language and am making a Payroll program addon
I have been making a matrix class (as a learning exercise) and I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.