0

I have a DataGrid and I want based of the data to determine the type of columns and create for these DataGrid. That mean that I see that the field is a date then i want to have a date picker in the DataGrid.

             Case "CURDATE"
                 Dim col As New DataGrid Template Column
                 col.Header = "Yay"

                 Dim fac As New FrameworkElement Factory

                 Dim b As Binding = New Binding ("CURDATE")
                 fac.SetValue (DatePicker.SelectedDateProperty b)
                 Dim cellil As DataTemplate = New Data Template

                 cellil.VisualTree = fac

                 col.CellEditingTemplate = cellil
                 Ctr.Columns.Add (col)
Amol Bavannavar
  • 2,062
  • 2
  • 15
  • 36
  • http://www.codeproject.com/Articles/444371/Creating-WPF-Data-Templates-in-Code-The-Right-Way – Federico Berasategui Jan 05 '15 at 18:54
  • BTW, saying *"WPF"* and *"Not XAML"* is like saying *"I'm going to drive this car, but I refuse to put my hands on the steering wheel, and will also keep my eyes closed during the ride."* - you're going to have a very unpleasant surprise, sooner or later. – Federico Berasategui Jan 05 '15 at 18:55
  • If you put all of the code in XAML, you will quickly see that your program will be as slow as a turtle. It will be better if you balance the code more. So that we don't have to wait for next christmas before it is ready. – Ludi Kuyper Jan 05 '15 at 21:10
  • `you will quickly see that your program will be as slow as a turtle` - Except if you know how to use XAML properly. I've done [all](http://stackoverflow.com/a/15469477/643085) [sorts](http://stackoverflow.com/a/15821573/643085) of XAML based UIs and never ever had any performance issues. At all. I seriously doubt your code (which btw doesn't even compile) can perform any better than properly written XAML. – Federico Berasategui Jan 05 '15 at 21:23
  • That you may think but I see no solution from you to put a date picker in a datagrid. And the piece of code that you see is part of a larger area, and if it would compile then I would not ask the question. But I would like to challenge you with the problem where it all started with. – Ludi Kuyper Jan 05 '15 at 21:43
  • `get you a date picker in a data grid` - Simply override the CellTemplate. – Federico Berasategui Jan 05 '15 at 21:45
  • The question is how to do this programmatically. – Ludi Kuyper Jan 05 '15 at 21:56
  • why do you want to do that? you're hard coding bindings and your code executes inside a strange switch statement. How is your hard coded code any more "dynamic" than hard coded XAML. Also, create a proper ViewModel and all your problems will magically disappear. – Federico Berasategui Jan 05 '15 at 22:14

0 Answers0