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

Date column question...

Greetings, I have a date column in a databound grid I am setting up with the following code. this.gridData.Model.ColStyles[5].CellType = "DropDownMonthCalendar"; this.gridData.Model.ColStyles[5].CellValue = System.DateTime.Now; As you can see I want to default in todays date for all new rows in the grid. This is a bulk entry screen. The odd behavior I am experiencing is the following: - When the screen is first loaded the first row is empty with the exception of the date column(this is what I want). As soon as I type in or select another column on this row the grid makes a new row(I have the enable add new property set to true) and removes the date value from my first row(what I don''t want). Essentially, I want this date column to default to today''s date for all new rows added, but allow the user to change it if they want. Cheers, JF

1 Reply

AD Administrator Syncfusion Team February 6, 2005 07:52 PM UTC

Jim, use the following code to fill the AddNew row with default values. The code will be execute the moment the user starts editing the AddNew row. this.gridDataBoundGrid1.Binder.EditModeChanged += new EventHandler(Binder_EditModeChanged); private void Binder_EditModeChanged(object sender, EventArgs e) { Syncfusion.Windows.Forms.Grid.GridModelDataBinder binder = sender as Syncfusion.Windows.Forms.Grid.GridModelDataBinder; if (binder.IsAddNew) { int rowIndex = binder.CurrentRowIndex; this.gridDataBoundGrid1.Model[rowIndex, 5].CellValue = System.DateTime.Now; } } Stefan >Greetings, > >I have a date column in a databound grid I am setting up with the following code. > >this.gridData.Model.ColStyles[5].CellType = "DropDownMonthCalendar"; > this.gridData.Model.ColStyles[5].CellValue = System.DateTime.Now; > >As you can see I want to default in todays date for all new rows in the grid. This is a bulk entry screen. > >The odd behavior I am experiencing is the following: >- When the screen is first loaded the first row is empty with the exception of the date column(this is what I want). As soon as I type in or select another column on this row the grid makes a new row(I have the enable add new property set to true) and removes the date value from my first row(what I don''t want). > >Essentially, I want this date column to default to today''s date for all new rows added, but allow the user to change it if they want. > >Cheers, >JF > >

Loader.
Live Chat Icon For mobile
Up arrow icon