c# - change button visibility based on selected employees -
my button btnaction disappears after first combobox cb1 textchanged event , never appears. want button visible when emp , tmp different, , invisible when aren't.
public class employee { [key] public int employeeid { get; set; } public string firstname { get; set; } public string lastname { get; set; } public int phone { get; set; } public int? salaryid { get; set; } public virtual salary salary { get; set; } public static bool operator ==(employee le, employee re) { if (le.firstname != re.firstname) homecoming false; if (le.lastname != re.lastname) homecoming false; if (le.phone != re.phone) homecoming false; if (le.salaryid != re.salaryid) homecoming false; if (le.salary != re.salary) homecoming false; homecoming true; } public static bool operator !=(employee le, employee re) { if (le.firstname == re.firstname) homecoming false; if (le.lastname == re.lastname) homecoming false; if (le.phone == re.phone) homecoming false; if (le.salaryid == re.salaryid) homecoming false; if (le.salary == re.salary) homecoming false; homecoming true; } } public class salary { [key] public int salaryid { get; set; } public string name { get; set; } public decimal? amount { get; set; } public static bool operator ==(salary ls, salary rs) { if (!ls.name.equals(rs.name)) homecoming false; if (ls.amount != rs.amount) homecoming false; homecoming true; } public static bool operator !=(salary ls, salary rs) { if (ls.name.equals(rs.name)) homecoming false; if (ls.amount == rs.amount) homecoming false; homecoming true; } }
and method called when combobox cb1 changes
public void cb1_ontextupdate(object sender, eventargs e) { if(datatype == 1) { employee tmp; tmp = emp/*es*/; tmp.firstname = cb1.text; if (tmp == emp/*es*/) this.btnaction.visible = false; if (tmp != emp/*es*/) this.btnaction.visible = true; } }
use this
public void cb1_ontextupdate(object sender, eventargs e) { if(datatype == 1) { this.btnaction.visible = !(cb1.text == emp.firstname) } }
but think should revise !=
operator. assume 2 employee (emp1, emp2) have same first name.
both emp1 == emp2
, emp1 != emp2
false!
c# .net winforms
No comments:
Post a Comment