2

I've got kind of a conceptual question. I am in the process of wrapping some statistics classes I wrote into WPF.

For that I have two DataGrid(-Views, currently in WinForms). In one DataGrid each row represents a column in the other. There I can set-up different variables (as in mathematical/statistical variables) with fields like "Header", "DataType", "ValidationBehaviour", "DisplayType". There I can also set-up how it should be displayed. Some Columns can automatically be set to ComboBoxColumns, some TextBoxColumns, and so on and so forth.

So, now once I've set-up these Columns I can go to the other grid and enter my data. I may, for instance, have generated (in grid 1) one Column called "Annual Gross Salary" with input of numerical values. Another Column called "Education" with "0=NoEducation", "1=College Level", "3=Universitary" etc. These labels are displayed as text in the combobox and my statistics engine behind then selects the respective value (0-3) for calculations (i.e. ordinal, nominal variables).

Sooo. In WinForms I could basically generate all the columns by hand in code and then add my data in the respective cells/rows. Now in WPF I thought that must be easy to realise. However, yesterday I got started with ICustomPropertyDescriptor which (maybe I was too thick) didn't give me the results I was looking for.

Basically, I just need to be able to dynamically generate columns (and rows) with different Layout, Controls (ComboBox, simple Input, DateTimes) based on the data that I have. But I don't really know how to go about it?

So here in summary:

  • DataGrid 1

    • Purpose is to display columns that have been specified in DataGrid 2
    • In rows, the user can add any kind of data in the rows below the columns that is allowed as to the columns specifications
  • DataGrid 2

    • Each row in this grid represents a column in DataGrid 1
    • Contains fields like Name/Header, DataType, Validation Behaviour, Default Value, Data Formatting, etc.
    • Also contains a function to be able to set-up how it should be displayed. The user can select from, for instance, ComboBoxColumn (and also add the available options), DateTime, normal TextBox, CheckBox etc.
    • After finishing adding a row it will automatically appear as a new column in DataGrid 1

I'd appreciate any kind of pointer into the right direction. Thanks very, very much in advance! :)

StatsMan
  • 21
  • 2

1 Answers1

-1

Look up DataTemplates. They do exactly this. The UI is determined by the related type.

Here is an MSDN article...

strattonn
  • 1,790
  • 2
  • 22
  • 41
  • A simple comment would be a more constructive than a downvote. Golden rule. Would you like someone to down vote your answers so whimsically? @Slyvain – strattonn Oct 29 '15 at 12:11
  • Not according to the community (http://meta.stackoverflow.com/questions/262038/how-to-flag-dead-links), but it did get your attention. Also understand a user's frustration finding a post related to his problem and the answer is a dead link, back to square one (the user was me this morning). A bit of code in the answer and/or a fix of link, and I can "un-whimsically" and with pleasure revert my down-vote. In instance this answer is, imho, useless. – Slyvain Oct 29 '15 at 12:24
  • 1
    @Miiir Indeed, 2.5 years later the link is now working. However my vote is locked by the system unless an edit is made on the answer. Would strattonn edit his answer to include a bit of code related to OP's question, I'll happily remove the downvote. – Slyvain May 04 '18 at 05:08