c# - UserControl in DataGridView -
c# - UserControl in DataGridView -
i made user command contains text box, button , month view. coded dgv column, cell , editing command classes per instructions here: http://msdn.microsoft.com/en-us/library/vstudio/7tas5c80(v=vs.100).aspx
then added references checkbook programme uses info grid view check register. particular column choosing date of transaction. when user clicks little button want month calendar drop down, date may chosen.
the problem when click button seems nil happens. when expand column/cell width & height can see calendar , take date.
i need know how create dgv cell alter size of entire user command 1 time button clicked , go normal after date chosen. happen cell , not create row height alter when have manually.
i need master because other cells require list boxes payee's , categories , calculator.
public class dgvtxtbtneditcontrol : txtbtn, idatagridvieweditingcontrol { // grid owns editing command private datagridview datagridview; // stores whether editing control's value has changed or not private bool valuechanged; // stores row index in editing command resides private int rowindex; public dgvtxtbtneditcontrol() { this.tabstop = false; } public datagridview editingcontroldatagridview { { homecoming datagridview; } set { datagridview = value; } } public object editingcontrolformattedvalue { { homecoming this.date; } set { this.editingcontrolformattedvalue = datetime.parse((string)value); } } public int editingcontrolrowindex { { homecoming rowindex; } set { rowindex = value; } } public bool editingcontrolvaluechanged { { homecoming this.valuechanged; } set { this.valuechanged = value; } } public bool repositioneditingcontrolonvaluechange { { homecoming false; } } public cursor editingpanelcursor { { homecoming cursors.default; } } public bool editingcontrolwantsinputkey(keys keydata, bool datagridviewwantsinputkey) { switch (keydata & keys.keycode) { case keys.right: case keys.left: case keys.tab: case keys.enter: datagridviewwantsinputkey = true; homecoming false; default: datagridviewwantsinputkey = false; homecoming true; } } public object geteditingcontrolformattedvalue(datagridviewdataerrorcontexts context) { homecoming editingcontrolformattedvalue; } public void prepareeditingcontrolforedit(bool selectall) { // no preparation needs done. } public void applycellstyletoeditingcontrol(datagridviewcellstyle datagridviewcellstyle) { this.font = datagridviewcellstyle.font; this.backcolor = datagridviewcellstyle.backcolor; this.forecolor = datagridviewcellstyle.forecolor; } protected override void ontextchanged(eventargs e) { // notify datagridview contents of cell // have changed. valuechanged = true; this.editingcontroldatagridview.notifycurrentcelldirty(true); base.ontextchanged(e); } private void notifydatagridviewofvaluechange() { if (!this.valuechanged) { this.valuechanged = true; this.datagridview.notifycurrentcelldirty(true); } } } public class calendarcell : datagridviewtextboxcell { #region default constants calendarcell // default values datagridviewcustomeditcell internal const int calendarcell_defaultmaxlength = 20; // default dimensions of static rendering bitmap used painting // of non-edited cells private const int calendarcell_defaultrenderingbitmapwidth = 100; private const int calendarcell_defaultrenderingbitmapheight = 22; #endregion #region private properties // type of cell's editing command private static type defaultedittype = typeof(dgvtxtbtneditcontrol); // bitmap used paint non-edited cells via phone call textbox.drawtobitmap [threadstatic] private static bitmap renderingbitmap; // textbox command used paint non-edited cells via phone call textbox.drawtobitmap [threadstatic] private static textbox paintingtextbox; #endregion #region constructor public calendarcell() : base() { // utilize short date format. this.style.format = "d"; // create thread specific bitmap used painting of non-edited cells if (renderingbitmap == null) { renderingbitmap = new bitmap(calendarcell_defaultrenderingbitmapwidth, calendarcell_defaultrenderingbitmapheight); } // create thread specific ellipsestextbox command used painting of non-edited cells if (paintingtextbox == null) { paintingtextbox = new textbox(); // properties need set 1 time lifetime of control: paintingtextbox.borderstyle = borderstyle.none; } // set default properties this.maxinputlength = calendarcell_defaultmaxlength; } #endregion public override void initializeeditingcontrol(int rowindex, object initialformattedvalue, datagridviewcellstyle datagridviewcellstyle) { // set value of editing command current cell value. base.initializeeditingcontrol(rowindex, initialformattedvalue, datagridviewcellstyle); dgvtxtbtneditcontrol ctl = datagridview.editingcontrol dgvtxtbtneditcontrol; // utilize default row value when value property null. if (this.value == null) { ctl.date = convert.tostring(this.defaultnewrowvalue); } else { ctl.date = convert.tostring(this.value); } //dgvtxtbtneditcontrol.size = new system.drawing.size(328, 190); } public override type edittype { { // homecoming type of editing command calendarcell uses. homecoming typeof(dgvtxtbtneditcontrol); } } public override type valuetype { { // homecoming type of value calendarcell contains. homecoming typeof(datetime); } } public override object defaultnewrowvalue { { // utilize current date , time default value. homecoming datetime.now; } } } public class calendarcolumn : datagridviewcolumn { public calendarcolumn() : base(new calendarcell()) { } public override datagridviewcell celltemplate { { homecoming base.celltemplate; } set { // ensure cell used template calendarcell. if (value != null && !value.gettype().isassignablefrom(typeof(calendarcell))) { throw new invalidcastexception("must calendarcell"); } base.celltemplate = value; } } } public partial class txtbtn : usercontrol { private string odate ; private string sdate; public string date { { odate = this.textbox1.text; homecoming odate; } set { odate = value; } } public string seldate { { sdate = convert.tostring(this.monthcalendar1.selectionrange); homecoming sdate; } set { sdate = value; } } public txtbtn() { initializecomponent(); this.btn1.visible = false; this.monthcalendar1.visible = false; this.textbox1.text = datetime.now.tostring("mm-dd-yyyy"); string value = this.textbox1.text; } protected override void ongotfocus(eventargs e) { base.ongotfocus(e); this.textbox1.focus(); } private void textbox1_click(object sender, eventargs e) { this.btn1.visible = true; } public void btn1_mouseclick(object sender, mouseeventargs e) { monthcalendar1.location = new point(e.x + btn1.location.x, e.y + btn1.location.y); monthcalendar1.visible = true; } public void monthcalendar1_datechanged(object sender, daterangeeventargs e) { this.textbox1.text = monthcalendar1.selectionstart.toshortdatestring(); this.monthcalendar1.visible = false; } public void monthcalendar1_dateselected(object sender, daterangeeventargs e) { e.start.date.toshortdatestring(); } private void txtmemo_textchanged(object sender, eventargs e) { this.ontextchanged(e); } public void btn1_click_1(object sender, eventargs e) { monthcalendar1.show(); } }
c# datagridview custom-cell
Comments
Post a Comment