How to change the contents of the grid?

I ask for programming.

That's my problem:

I have a WPF window, with a ComboBox at the top.

When the user selects an item in combobox, it depends on the choice, then the corresponding item will be displayed below it, for example: if you use Display Display from combobox, then the item in the Grid will change to ListView; and when the user selects "Add from combobox", the element in the Grid will change to a form (text fields).

Should I create several Grid, collapse them and show them only when the user makes a choice? Or any other more brilliant ideas?

Thanks.

+4
source share
3 answers

Two ways are possible:

You add one panel containing the controls needed for each of the items in the drop-down list. You can hide all of them and on SelectedIndexChanged , you can display the corresponding panel. This will require more memory, but the implementation is simpler.

Another way is to have one panel and display controls at run time on SelectedIndexChanged . This will require less memory but will be difficult to implement. Also, rendering at runtime may take some extra time (therefore bandwidth).

+1
source

Place a UserControl in the cell and set its Content according to the control selected in ComboBox.

+4
source

What you can do is place the panel (like Grid , DockPanel ) under the drop-down list and based on its choice dynamically add / remove controls on the panel.

For example: if the user selects Display, remove all Panel children and add a GridView . If Add is selected, remove all children and add a TextBox .

After adding, attach an event handler in the code to perform the action you want to perform.

+1
source

Source: https://habr.com/ru/post/1343874/


All Articles