We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

MonthCalendar celltype issue

Thread ID:

Created:

Updated:

Platform:

Replies:

41952 Mar 15,2006 04:22 PM Mar 16,2006 09:53 AM Windows Forms 2
loading
Tags: GridControl
Hui Zhong
Asked On March 15, 2006 04:22 PM

Based on a previous subject :"How do I supress keystrokes in a month calendar cell" at your forum, I added some more code to implement some other keystroke for day ++, or day --. Please try the example code attached, and let me know why the second key "-" or "+" will get the error " object reference not set to an instance of an object" at DateTime dat = (DateTime)cc.Renderer.ControlValue;". Thanks.

Forum_407351.zip

Administrator [Syncfusion]
Replied On March 16, 2006 04:45 AM

Hi Hui, The mentioned issue is caused because of a null value (cc.Renderer.ControlValue) is tried to cast as DateTime type. To get the display text here, the Control.Text must be used. Below is a code snippet. void gridControl1_CurrentCellValidateString(object sender, GridCurrentCellValidateStringEventArgs e) { GridCurrentCell cc = this.gridControl1.CurrentCell; if (cc.Renderer.StyleInfo.CellType == "MonthCalendar") if (e.Text.IndexOf("t") > -1) { e.Cancel = true; cc.CancelEdit(); cc.Renderer.Control.Text = DateTime.Now.ToString(); this.gridControl1.RefreshRange(cc.RangeInfo, true); } else if(e.Text.IndexOf("+") > -1 || e.Text.IndexOf("-") > -1) { e.Cancel = true; if (cc.Renderer.Control.Text.Trim() != "") { cc.CancelEdit(); DateTime dat = Convert.ToDateTime(cc.Renderer.Control.Text); int diff = e.Text.IndexOf("+") > -1 ? 1 : -1; cc.Renderer.Control.Text = dat.AddDays(diff).ToString("d"); dt.Rows[cc.RowIndex - 1][cc.ColIndex - 1] = cc.Renderer.Control.Text; this.gridControl1.RefreshRange(cc.RangeInfo, true); } } } Regards, Calvin.

Hui Zhong
Replied On March 16, 2006 09:53 AM

Thanks, Calvin. It worked. However, I can''t figure out why cc.Renderer.ControlValue is null though there is validate date in the cell. >Hi Hui, > >The mentioned issue is caused because of a null value (cc.Renderer.ControlValue) is tried to cast as DateTime type. To get the display text here, the Control.Text must be used. Below is a code snippet. > > > void gridControl1_CurrentCellValidateString(object sender, GridCurrentCellValidateStringEventArgs e) > { > GridCurrentCell cc = this.gridControl1.CurrentCell; > if (cc.Renderer.StyleInfo.CellType == "MonthCalendar") > if (e.Text.IndexOf("t") > -1) > { > e.Cancel = true; > cc.CancelEdit(); > cc.Renderer.Control.Text = DateTime.Now.ToString(); > this.gridControl1.RefreshRange(cc.RangeInfo, true); > > } > else > if(e.Text.IndexOf("+") > -1 || e.Text.IndexOf("-") > -1) > { > e.Cancel = true; > if (cc.Renderer.Control.Text.Trim() != "") > { > cc.CancelEdit(); > DateTime dat = Convert.ToDateTime(cc.Renderer.Control.Text); > int diff = e.Text.IndexOf("+") > -1 ? 1 : -1; > cc.Renderer.Control.Text = dat.AddDays(diff).ToString("d"); > dt.Rows[cc.RowIndex - 1][cc.ColIndex - 1] = cc.Renderer.Control.Text; > this.gridControl1.RefreshRange(cc.RangeInfo, true); > } > > } > } > >Regards, >Calvin.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;