I have text column in grid that shows date. I cannot use datecolumn, because sql field set as text. How can I show date picker when user click on cell?
thanks
Hi,
You can use a TemplateColumn with a TextBlock in the ItemTemplate and a DatePicker in the editor template.
Then you can setup your editing options like so:
<ig:XamWebGrid.EditingSettings>
<ig:EditingSettings AllowEditing="Cell" IsMouseActionEditingEnabled="SingleClick"/>
</ig:XamWebGrid.EditingSettings>
-SteveZ
Stephen,
I am currently doing just what you mentioned, but I have binding issues when I edit the date in the DatePicker and then tab out of the cell or click on another cell. The date does not update. I read in other forum posts that this is an issue with the DatePicker, so I decided to give the DateColumn a try. I need it to work like the previous configuration though. I need the cell to look like a TextBlock when it is inactive and change to the DatePicker only when it is active so that it can be edited. Can you do this with the TextColumn? If not, do you know of any way (hack) to make the DatePicker work corectly in the TemplateColumn?
Bob
Hi Bob,
I wouldn't call this hack,
But one approach would be to create a custom column derived from DateColumn and DateColumnContentProvider.
Here is an article on how to create a custom column: http://blogs.infragistics.com/blogs/devin_rader/archive/2010/07/08/creating-custom-columns-for-xamgrid.aspx
Basically, you'd override ResolveDisplayElement in your derived ColumnContentProvider, and return a TextBlock instead of a DatePicker
Hope this helps
Steve,
I thought this solved all my issues, but I still have one. The date now updates when you are entering the date in the textbox portion of the DatePicker and it loses focus to another cell by tabbing or clicking. The problem is that the date does not update if you loose focus to a control outside of the xamGrid. If I click on a textbox or button that is not part of the grid, then the date in the cell goes back to the previous value. I looked at the cell during the CellExitingEditMode and the grid LostFocus events, and it just doesn't have the changed date. Is there a place I can force the binding to update?
I wasn't able to reproduce the issue.
Here is my custom DateColumn and ContentProvider:
public class CustomDateColumn : DateColumn
{ protected override ColumnContentProviderBase GenerateContentProvider() { return new CustomDateColumnContentProvider(); } } public class CustomDateColumnContentProvider : DateColumnContentProvider { TextBlock _tb = new TextBlock(); public override FrameworkElement ResolveDisplayElement(Cell cell, Binding cellBinding) { this._tb.SetBinding(TextBlock.TextProperty, cellBinding); return this._tb; } }
I already thought that it might be my custom implementation, so I tried the unmodified DateColumn before my last post and it works exactly the same. I am on the release version of 10.2 if that helps.
Ah,
Thats probably it. There were definitely fixes made in that area, since the 10.2 release.
You should get the latest SR.