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. Image for the cookie policy date

how to make the edit bit of the MonthCalendar readonly...

how can i make the edit bit of the MonthCalendar readonly... basically beacuse if i set a format eg "ddd dd MMM yyyy" then it insists the user types it in in that format too, so they get 29 Sep 2004 is not a vlid date!

6 Replies

AD Administrator Syncfusion Team August 13, 2004 04:21 AM

I am not sure I understand what you are asking. Is it that you want to make it impossible for the user to type into the grid cell? If so, here are a couple of ways you can do this. One is to set the style.ReadOnly = true for that cell. Another is to handle the CurrentCellStartEditing event, and if grid.CurrentCell.RowIndex and grid.CurrentCell.ColIndex point to this cell, then set e.Cancel = true.


AD Administrator Syncfusion Team August 15, 2004 11:41 AM

wont making it readonly mean that the user cant use the drop down control i''ll give the begin edit a try though.. although as i say the ''real'' problem is that i think that a user should be able to enter a date in any standard form and not the one thats its beeing formatted in....ie its nice to see the day of the week, but a user shouldn''t be forced to enter it....


AD Administrator Syncfusion Team August 15, 2004 02:54 PM

ReadOnly will prevent changing the cell value. Here are two events that you can handle to prevent typing into the cell, but still allow changing from the dropdown.
private void gridDataBoundGrid1_CurrentCellStartEditing(object sender, CancelEventArgs e)
{
	GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
	if(cc.ColIndex == 2)
	{
		e.Cancel = true;
	}
}

private void gridDataBoundGrid1_CurrentCellCloseDropDown(object sender, PopupClosedEventArgs e)
{
	GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
	if(cc.ColIndex == 2)
	{
		cc.ConfirmChanges();
	}
}


PI Pierre-Luc February 27, 2006 04:05 PM

Hello there, I have the same needs here, and I''m coding in VB.net. I attached a sample of the way I used the code you just gave, but somehow when you choose a date in the calendar dropdown and then switch the focus to anything else, the date in the cell disapears. did I do something wrong? I also need, when the date will be available, to be able to Update a database field on an event that happens when the date as been selected, can you please tell me which it would be? Thanks for being so much support to us all Pierre-Luc

MonthCalendarExemple.zip


ST stanleyj Syncfusion Team February 28, 2006 12:30 AM

Hi Pierre-Luc, Try handling CurrentCellKeyDown and CurrentCellKeyPress handlers to block the keyboard entries instead of CurrentCellStartEditing and CurrentCellCloseDropDown. Private Sub gridControl1_CurrentCellKeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Dim cc As GridCurrentCell = Me.gridControl1.CurrentCell If cc.ColIndex = 2 AndAlso (e.KeyCode = Keys.Delete OrElse e.KeyCode = Keys.Back) Then e.Handled = True End If End Sub Private Sub gridControl1_CurrentCellKeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Dim cc As GridCurrentCell = Me.gridControl1.CurrentCell If cc.ColIndex = 2 Then e.Handled = True End If End Sub Best regards, Stanley


PI Pierre-Luc February 28, 2006 10:10 AM

wow! thanks ^_^ it worked perfectly Pierre-Luc

Loader.
Live Chat Icon For mobile
Up arrow icon