I have a WPF application that uses a TabControl. Each TabItem will contain a datagrid. When the application starts up, there is one TabItem that loads by default that displays an “Accounts” datagrid. This datagrid displays only account information. The user can then choose to add new Tabs. For each tab that is added, I need the same datagrid to be loaded. It is NOT the same datagrid that is used for the Accounts TabItem. The new datagrid will be used to enter transactions. How can I define a datagrid that I can use in each newly added TabItem, but is different than the original datagrid on the first TabItem?
Share
So if I understand correctly what you want is a default
DataGridfor the firsttabitemand then for each newtabitemsamedatagrid.Problem here is that a single
DataGridcannot be part of TwoTabItemsat the same time. So what you would have to do it first declare aDataGridin a scope where it can be accessed in the code behind. Next, when user adds a newtabitem, first time, add atab itemdynamically in thetab controland setcontentequal toDataGrid. When user clicks the add new tab item again, remove thecontentof tab item which previously hadDataGridand then Adddatagridin the newtab item. You will also have to handle theselection changeevent of tabs and inside that event you will have to removeDataGridfrom last selected item and put in the newly selected item.I am not sure you really need this same dataGrid for different tab items thing or not but think before implementing this approach about other possible solutions