Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Looking at your code it seems to me that you're adding text items to the ListBox, so of course it's not easy to get the salary from that.</p> <p>Instead, you should pass the Employee object to the the listbox to keep all the necessary informations; in this way, your adding method would be :</p> <pre><code> private void btnSave_Click(object sender, EventArgs e) { var empid = Convert.ToInt32(txtEmployeeID.Text); var empfirstname = Convert.ToString(txtEmployeeFirstName.Text); var emplastname = Convert.ToString(txtEmployeeLastName.Text); var empsalary = Convert.ToDouble(txtSalary.Text); var emp = new Employee(empid, empfirstname, emplastname, empsalary); lstEmployeeData.Items.Add(emp); } </code></pre> <p>Of course, to get the desired display text you need to re-define <code>ToString()</code> method of Employee, for example like this:</p> <pre><code> class Employee { // other methods... public override string ToString() { return this.EmployeeToString(); } } </code></pre> <p>Finally, when the button "show employee having the minimum salary" is clicked you should simply do something like this:</p> <pre><code>private void btnLowestSalary_Click(object sender, EventArgs e) { var minSalary = lstEmployeeData.Items.OfType&lt;Employee&gt;().Min(x =&gt; x.Salary); var empWithMinSalary = lstEmployeeData.Items.OfType&lt;Employee&gt;() .First(x =&gt; x.Salary == minSalary); string msg = string.Format("{0} has the lowest salary of {1}", empWithMinSalary.EmployeeFirstName, minSalary); MessageBox.Show(msg); } </code></pre> <p><strong>EDIT :</strong></p> <p>In case more than one employee have the same salary you can do something like this:</p> <pre><code>private void btnLowestSalary_Click(object sender, EventArgs e) { var minSalary = lstEmployeeData.Items.OfType&lt;Employee&gt;().Min(x =&gt; x.Salary); var empsWithMinSalary = lstEmployeeData.Items.OfType&lt;Employee&gt;() .Where(x =&gt; x.Salary == minSalary); foreach(var e in empsWithMinSalary) { string msg = string.Format("{0} has the lowest salary of {1}", e.EmployeeFirstName, minSalary); MessageBox.Show(msg); } } </code></pre> <p>Or better:</p> <pre><code>private void btnLowestSalary_Click(object sender, EventArgs e) { var minSalary = lstEmployeeData.Items.OfType&lt;Employee&gt;().Min(x =&gt; x.Salary); var empsWithMinSalary = lstEmployeeData.Items.OfType&lt;Employee&gt;() .Where(x =&gt; x.Salary == minSalary); string names = ""; foreach(var e in empsWithMinSalary) names += Environment.NewLine + e.EmployeeFirstName; string msg = string.Format("The following emplyoees have the lowest salary of {0} : {1}", minSalary, names); MessageBox.Show(msg); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload