Hello,
I was wondering if you can give me some advice on how to achieve the following:
The user is asked (e.g. by 3 textblocks with content "Min. Value", "Max. Value" and "step size") to enter the min./max values and the step size he wishes to be used. The only thing that is fixed is the amount of columns (e.g. 2 in this case).
For example:
The user enters "Min. Value = 20", "Max. Value = 100", "Step Size = 10".
The table generated should now have 9 rows with the values 20 - 100 in the first column.
The second column should calculate values depending on the values in the first row.
Furthermore both columns should be boundable (I.e. unbound column for the second row is most likely not going to work).
Unfortunately I have to stick with XamGrid.
It would be really nice if you could help me achieving this. Thank you.
Kind regards,
Julian
Hello Julian,
Here is a sample showcasing how to implement your desired behavior. You enter some text in the box labeled text and a number in the numbers box then press generate grid which will use that info to create the grid. You can also edit a cell in the label column then when you exit editing mode in the cell it will reflect in the corresponding label box.
Let me know if you have any additional questions.
Regards.
Nicholas
wpfSmartXamGrid.zip
Hello Nicholas,
thank you for your answer.
Would it be possible for you to provide a simple (small example) of how to achieve this without using MVVM ? Thank you.
What you can do is use the method mentioned previously to set up the initial grid. Then when users go to edit the editable column you can use the ExitEditingCell event to edit the datatable. You can use the cells row and column properties to check that the user is editing in the correct place. Since you want this in MVVM you will need to implement it as a behavior.
Relevant docs: https://es.infragistics.com/help/wpf/infragisticswpf.controls.grids.xamgrid~infragistics.controls.grids.exiteditingcelleventargs_members
https://es.infragistics.com/help/wpf/infragisticswpf.controls.grids.xamgrid~infragistics.controls.grids.cell_members
https://blog.jayway.com/2013/03/20/behaviors-in-wpf-introduction/
thank you for the reply.
I've been looking to this:
https://es.infragistics.com/samples/wpf/grid/binding-to-data-table
However, in this example nothing is being calculated dynamically depending on the values in the first column entered by the user. This is also a requirement that I have. Otherwise I could just stick to TextColumns but (apparently) I can't calculate values (depending on first column value), show them and at the same time enable twoway binding. It would be nice if this could be done using the MVVM pattern.
I've been trying to use the ValueConverter for this but the twoway binding is not working then. Thank you in advance.
For clarification why I would appreciate this to be done with TextColumns: The ItemsSource of my XamGrid is already set to to XamComboEditor's SelectedValue with Twoway bindings.
I have been investigating into your requirement to dynamically generate a data source for the XamGrid and I would recommend using a DataTable for this. You can create the DataTable dynamically based on the user's input and then set the ItemsSource of the XamGrid to this DataTable's DefaultView.
Let me know if you need additional assistance.