Displaying a grid of mixed controls from tabular data: solved
-
NB: The solution is at the end. We need to configure a hard ware device, which provides configuration settings as tabular data. There are lots of different sets of tabular data. We want to display a given table in a view, so that the user can edit the fields. All fields in a given row have the same kind of data e.g. integer. However, one row might display integers, another might display a combo box, and another a check box. The problem is how to automatically create the WPF view and view model code. The nature of the data in each table is defined in an XML file. Unfortunately for one table the number of columns is defined by a value in another table which is only known at run-time. Thus we can create some tables at build time, but one must be created at run-time. I created a parser which generates the WPF view and view model for each table of data. This parser can be run at run-time to generate view and view model source code, which is then compiled at run-time, and displayed. So far so good. This works well with one exception, as the number of fields is almost always modest. Unfortunately one table has ~120,000 cells, and the resulting view model will not run as the number of controls exceeds the maximum allowed by WPF. The view will display and looks good. Clearly having so many properties in a view model is a tad ridiculous and crude. So, we need a more elegant solution, and one which allows the values to be displayed in a table with cells all nicely aligned. The view model contains a list of field objects, each of which provides data in the correct format for the corresponding table cell e.g. "true" and "false" for tick box. Is it possible to create a DataGrid, such that it gets its data from my table of fields, and displays the correct kind of control dependent on the nature of the data (which my field object knows)? Thus row 0 might be tick boxes, row 1 edit boxes, and row 2 combo boxes? ================================================================== Solution: I came across some example code that almost solved our problem, and with some changes it does the job in my demo application which I will explain below in case anyone finds this useful. The link is as follows: WPF DataGrid and binding to matrix of objects using UserControl per cell[
-
NB: The solution is at the end. We need to configure a hard ware device, which provides configuration settings as tabular data. There are lots of different sets of tabular data. We want to display a given table in a view, so that the user can edit the fields. All fields in a given row have the same kind of data e.g. integer. However, one row might display integers, another might display a combo box, and another a check box. The problem is how to automatically create the WPF view and view model code. The nature of the data in each table is defined in an XML file. Unfortunately for one table the number of columns is defined by a value in another table which is only known at run-time. Thus we can create some tables at build time, but one must be created at run-time. I created a parser which generates the WPF view and view model for each table of data. This parser can be run at run-time to generate view and view model source code, which is then compiled at run-time, and displayed. So far so good. This works well with one exception, as the number of fields is almost always modest. Unfortunately one table has ~120,000 cells, and the resulting view model will not run as the number of controls exceeds the maximum allowed by WPF. The view will display and looks good. Clearly having so many properties in a view model is a tad ridiculous and crude. So, we need a more elegant solution, and one which allows the values to be displayed in a table with cells all nicely aligned. The view model contains a list of field objects, each of which provides data in the correct format for the corresponding table cell e.g. "true" and "false" for tick box. Is it possible to create a DataGrid, such that it gets its data from my table of fields, and displays the correct kind of control dependent on the nature of the data (which my field object knows)? Thus row 0 might be tick boxes, row 1 edit boxes, and row 2 combo boxes? ================================================================== Solution: I came across some example code that almost solved our problem, and with some changes it does the job in my demo application which I will explain below in case anyone finds this useful. The link is as follows: WPF DataGrid and binding to matrix of objects using UserControl per cell[
Leif Simon Goodwin wrote:
Unfortunately one table has ~120,000 cells, and the resulting view model will not run as the number of controls exceeds the maximum allowed by WPF
Virtualization will be your friend here. You don't actually need to hold all those cells in memory - especially as you wouldn't be able to physically see them on the screen at the same time.
This space for rent
-
NB: The solution is at the end. We need to configure a hard ware device, which provides configuration settings as tabular data. There are lots of different sets of tabular data. We want to display a given table in a view, so that the user can edit the fields. All fields in a given row have the same kind of data e.g. integer. However, one row might display integers, another might display a combo box, and another a check box. The problem is how to automatically create the WPF view and view model code. The nature of the data in each table is defined in an XML file. Unfortunately for one table the number of columns is defined by a value in another table which is only known at run-time. Thus we can create some tables at build time, but one must be created at run-time. I created a parser which generates the WPF view and view model for each table of data. This parser can be run at run-time to generate view and view model source code, which is then compiled at run-time, and displayed. So far so good. This works well with one exception, as the number of fields is almost always modest. Unfortunately one table has ~120,000 cells, and the resulting view model will not run as the number of controls exceeds the maximum allowed by WPF. The view will display and looks good. Clearly having so many properties in a view model is a tad ridiculous and crude. So, we need a more elegant solution, and one which allows the values to be displayed in a table with cells all nicely aligned. The view model contains a list of field objects, each of which provides data in the correct format for the corresponding table cell e.g. "true" and "false" for tick box. Is it possible to create a DataGrid, such that it gets its data from my table of fields, and displays the correct kind of control dependent on the nature of the data (which my field object knows)? Thus row 0 might be tick boxes, row 1 edit boxes, and row 2 combo boxes? ================================================================== Solution: I came across some example code that almost solved our problem, and with some changes it does the job in my demo application which I will explain below in case anyone finds this useful. The link is as follows: WPF DataGrid and binding to matrix of objects using UserControl per cell[
The fact it "looks" like a grid, doesn't mean you need to use a "DataGrid" control. You haven't even established a "view port"; i.e. how many cells you expect to "see" at any one time. Then you can start thinking in terms of "pages" (and virtualization; as has been already suggested).
"(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal
-
The fact it "looks" like a grid, doesn't mean you need to use a "DataGrid" control. You haven't even established a "view port"; i.e. how many cells you expect to "see" at any one time. Then you can start thinking in terms of "pages" (and virtualization; as has been already suggested).
"(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal
Thanks. The number of cells visible is determined by the user and the monitor size, but roughly 30 by 30 say. However, it is a variable.