c# - Is it possible to textchanged event to occur only when textBox is focused? -
i have method this.
public void checkemployee() { connectionstringsettings myconnectionstring = configurationmanager.connectionstrings["librarysystem.properties.settings.libraryconnectionstring"]; using (sqlconnection mydatabaseconnection = new sqlconnection(myconnectionstring.connectionstring)) { mydatabaseconnection.open(); using (sqlcommand mysqlcommand = new sqlcommand("select * employee employeeid = '" + employeeidtextbox.text + "' ", mydatabaseconnection)) using (sqldatareader sqlreader = mysqlcommand.executereader()) { if (sqlreader.read()) { string employeeid = sqlreader.getint32(0).tostring(); string name = sqlreader.getstring(1); string address = sqlreader.getstring(2); employeeidtextbox.text = employeeid; nametextbox.text = name; addresstextbox.text = address; } } } }
and have write code this.
private void employeeidtextbox_textchanged(object sender, eventargs e) { checkbook(); nametextbox.clear(); addresstextbox.clear(); } private void nametextbox_textchanged(object sender, eventargs e) { checkbook(); employeetextbox.clear(); addresstextbox.clear(); }
the problem nametextbox_textchanged triggers when input in employeeidtextbox because method gets value database , display nametextbox.
is possible nametextbox_textchanged occur when nametextbox focused? , vice versa.
thank :)
off top of head, try ignoring textchanged
event if nametextbox
not focused - this:
private void nametextbox_textchanged(object sender, eventargs e) { if (nametextbox.isfocused) { checkbook(); employeetextbox.clear(); addresstextbox.clear(); } }
Comments
Post a Comment