Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating tabitems depending on selecting menuitems:

Dim myTabItem As New TabItem()
myTabItem.Header = "TabPage" & (tc_main.Items.Count + 1)
tc_main.Items.Add(myTabItem)

Then I want to populate the created tabitem with listviews and buttons ...
Posted

1 solution

Hi,
use the same way you did for creating TabItem. like following,
VB
Dim myTabItem As New TabItem()
myTabItem.Header = "TabPage" & (tc_main.Items.Count + 1)
tc_main.Items.Add(myTabItem)

'Add ListView like following,
Dim myContainerGrid As New Grid()
Dim myListView As New ListView()
myListView.Items.Add("List Item 1")
myListView.Items.Add("List Item n")
myContainerGrid.Content = myListView
myTabItem.Content = myContainerGrid

Or, you can also use the index of created TabItem. When you are adding TabItem using tc_main.Items.Add(myTabItem) method, it returns an integer value, this value is the index of the added TabItem in the TabControl.
By using this index, you can get your dynamically created TabItem like,
VB
Dim index As Integer = tc_main.Items.Add(myTabItem)
Dim AddedItem As TabItem = tc_main.Items(index) As TabItem

'Add ListView like following,
Dim myContainerGrid As New Grid()
Dim myListView As New ListView()
myListView.Items.Add("List Item 1")
myListView.Items.Add("List Item n")
myContainerGrid.Content = myListView
AddedItem.Content = myContainerGrid

Like this you can any controls.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900