c# - What events to handle in DataGridView for inline update / add / delete? -
essentially want user experience can go dgv , edit data (ie click cell, type stuff, hit enter), , have go database. can handle sql side, events should handle can figure out if user has done add, delete, or update?
thanks.
string lastcelltext; textbox textbox; private void datagridview1_editingcontrolshowing(object sender, datagridvieweditingcontrolshowingeventargs e) { if (e.control textbox) { textbox = e.control textbox; textbox.textchanged += textbox_textchanged; } } void textbox_textchanged(object sender, eventargs e) { //your actions } private void datagridview1_cellendedit(object sender, datagridviewcelleventargs e) { if (textbox.text ==string .empty ) { //do delete } if (textbox.text != lastcelltext) { //if textbox.text in database update else add } lastcelltext=textbox.text; textbox.textchanged -= textbox_textchanged; }
Comments
Post a Comment