c# - change cell in datagridview to empty value -
i have method change cell in datagridview , works fine when rewrite text (string) .
want example rewrite email empty value , dont know how this.
i can rewrite email email (string string)
method change cell :
public void changecellemail(int col, string[] emails) { string sep = ";"; string text = ""; foreach (datagridviewcell cell in datagridview1.selectedcells) { (int = 0; < emails.length ;i++) { if (emails[i].tostring().trim() != "") { text = text + emails[i] + sep ; datagridview1.rows[cell.rowindex].cells[col].value = text; } } } }
the calling code of method is
string mail = txtbox1.text; string mail1 = txtbox2.text; string mail2 = txtbox3.text; string mail3 = txtbox4.text; string mail4 = txtbox5.text; string[] mails = new string[] { mail, mail1, mail2, mail3, mail4 }; frm1.changecellemail(2, mails); this.dispose();
thanks guys .
using following code can pass in 5 complete email address's of / "empty" , tempvar
contain correct data.
public form1() { initializecomponent(); const string mail = "first"; const string mail1 = "second"; const string mail2 = "third"; const string mail3 = ""; const string mail4 = "fifth"; var mails = new string[] { mail, mail1, mail2, mail3, mail4 }; changecellemail(2, mails); } public void changecellemail(int col, string[] emails) { var sep = ";"; var text = ""; var tempvar = ""; //new temp variable (representing datagrid.value) (int emaillist = 1; emaillist < 5; emaillist++) { (var = 0; < emails.length; i++) { if (emails[i].trim() != "") { text = text + emails[i] + sep; tempvar = text; } else { tempvar = string.empty; } } } }
check tempvar on each loop , you'll see referring to.
Comments
Post a Comment