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 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
-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
Thanks Steve,
I am crerating columns dynamicaly in code. What is the best way to do that?
Also, I got datepicker to work, but when I cick on it, it shows <m/dd/yyy> in cell and my data in cell disappeared.
Any help?
Thanks
Hi,
First, i'm guessing you're using the ColumnLayout Assigned event to build your columns?
May i ask why? That event was designed for specific scenarios where you may want to interrupt the creation of ColumnLayouts to achieve some advanced use cases. It wasn't really designed for creating and adding columns to the ColumnLayout. So, if thats not the purpose in which you're using it, i'd recommend creating the columns, before you assign your ItemsSource. B/c otherwise, you're going to cause the grid to have to do a bunch of catch up and reconfiguration, which can be costly.
Second, a TemplateColumn requires a DataTemplate, which is something that is not easy to create in the code behind. The following post talks about the 2 different ways which it can be achieved:
http://forums.infragistics.com/forums/p/33915/184359.aspx#184359
Steve,
I have this in code
e.ColumnLayout.Columns.Add(
new TemplateColumn() {HeaderText = col.DisplayName,Key = col.ColumnName,
),
How can i add datepicker in there? Can you help?