Execute function based on Selected item from drop down list

This topic contains 1 reply, has 1 voice, and was last updated by  Rhys 1 month ago.

  • Author
    Posts
  • #99217

    Rhys
    Participant

    Note: This is practice, details that follow are not confidential.

    Hello all,

    I have a drop down box containing 2 employees. I want to populate an hourly rate (£) text box which will be the result of which Employee is selected from the drop down. The hourly rate values are hard coded for now.

    Below is the function I call for setting the Hourly Rate.

    function SetHourlyRate
    {	
    	param(
    		$WhichEmployee = $($EmployeeDropDownBox.SelectedItem)
    	)
    	
    	if ($WhichEmployee = "Mike Smith")
    	{ $HourlyRateTextBox.Text = "£11.60" }
    	
    	if ($WhichEmployee = "David Bloggs")
    	{ $HourlyRateTextBox.Text = "£12.20" }	
    }
    

    Below is the drop down box with selected value event:

    $EmployeeList = @("Mike Smith", "David Bloggs")
    foreach ($Employee in $EmployeeList)
    {
    	$EmployeeDropDownBox.Items.Add($Employee)
    }
    $EmployeeDropDownBox.add_SelectedValueChanged({ SetHourlyRate })
    

    Selecting any employee sets the rate to £12.20, I am unable to display the £11.60 value. Is my $WhichEmployee variable not matching the if statements of "Mike Smith" or "David Bloggs"? I have tried using .selecteditem.ToString() also which did not work. The function seems to display whichever value is displayed last.

    Thanks

  • #99222

    Rhys
    Participant

    Resolved. Daft error on my part, operator "=" should be written as -eq, hence why my statements were failing. Apologies if you were taking part. thanks

You must be logged in to reply to this topic.