c# - Changing DateTime Format from one form to another -


i wish make "tdate" format "d, mmm, yyyy" , send 1 form has data grid view different form contains textbox.

so far tried make as:

 frm.txtdate.text = (this.dgvevents.currentrow.cells[2].value.tostring("d, mmm, yyyy")); 

this code of class :-

public int createticket(string tname, datetime tdate, string type, string venue) {     eventticketentities database = new eventticketentities();     ticket t = new ticket();     t.ticketname = tname;     t.ticketdate = tdate;     t.tickettype = type;     t.ticketvenue = venue;     database.tickets.add(t);//we add our promoter our advertiser table!     return database.savechanges(); //returns affected rows .... } 

and code show new form when "proceed" button clicked.

public void btnproceed_click(object sender, eventargs e) {     ticketform frm = new ticketform();       frm.txtname.text = (this.dgvevents.currentrow.cells[1].value.tostring());      frm.txtdate.text = (this.dgvevents.currentrow.cells[2].value.tostring());      frm.txttype.text = (this.dgvevents.currentrow.cells[3].value.tostring());      frm.txtvenue.text = (this.dgvevents.currentrow.cells[4].value.tostring());     //pass selected index of combobox       frm.show(); } 

cell.value of type object, need cast datetime apply customized formatting.

((datetime)this.dgvevents.currentrow.cells[2].value)                    .tostring("d, mmm, yyyy", cultureinfo.invariantculture); 

also supply cultureinfo.invariantculture keep date separator ,.

this work, if data in your cell datetime type begin with, otherwise end exception


Comments

Popular posts from this blog

methods - python can't use function in submodule -

Java 3D LWJGL collision -

c# - ErrorThe type or namespace name 'AxWMPLib' could not be found (are you missing a using directive or an assembly reference?) -