Hi everyone,
Firstly, thank you for taking the time out to read this post.
I'm having trouble trying to loop through a WPF ListBox control to find a nested TextBox in VB.net 3.5.
Here is my UI structure:
TabControl > TabItem > UserControl > Grid > ListBox > ListBoxItem > Grid > TextBox
I have a page that Contains a TabControl. When the TabControl loads, I loop through each TabItem to dynamically add a UserControl which contains a grid, where the first grid row contains a ListBox. In each ListBox I dynamically add 8 ListItems, where each item is DataTemplate that contains another Grid that houses an Image, TextBox and Button.
I need to loop through all of the items to find the textbox nested in each ListBoxItem. I've managed to drill down the the ListBoxItem level but I don't know how to dig further down to find the TextBox.
Here is my VB code so far:
Any advice is greatly appreciated.
Thank you for your time,
Rob
Firstly, thank you for taking the time out to read this post.
I'm having trouble trying to loop through a WPF ListBox control to find a nested TextBox in VB.net 3.5.
Here is my UI structure:
TabControl > TabItem > UserControl > Grid > ListBox > ListBoxItem > Grid > TextBox
I have a page that Contains a TabControl. When the TabControl loads, I loop through each TabItem to dynamically add a UserControl which contains a grid, where the first grid row contains a ListBox. In each ListBox I dynamically add 8 ListItems, where each item is DataTemplate that contains another Grid that houses an Image, TextBox and Button.
I need to loop through all of the items to find the textbox nested in each ListBoxItem. I've managed to drill down the the ListBoxItem level but I don't know how to dig further down to find the TextBox.
Here is my VB code so far:
VB.NET:
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]'Loop through TabItems in TabControl[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] tabItems [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = 0 [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] tabInspection.Items.Count - 1[/SIZE]
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000] 'Create object of the current TabItem[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] tabItem [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] TabItem = tabInspection.Items(tabItems)[/SIZE]
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000] 'Continue if TabItem Header is not Save and Exit[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] If[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] tabItem.Header <> [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Save and Exit"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000] 'Find ListBox that is nested in UserControl > Grid[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] For[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ctrl [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Control [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] tabItem.Content.Content.Children[/SIZE]
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000] 'Check if control found is a ListBox[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] If[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ctrl.GetType().FullName = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]GetType[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](ListBox).FullName [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000] 'Create Control object of the ListBox[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] lstBox [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ListBox = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]CType[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](ctrl, ListBox)[/SIZE]
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000] 'Loop Through ListBox items[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] For[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] item [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] lstBox.Items[/SIZE]
[SIZE=2] MessageBox.Show(item.ToString, [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"List Box Item"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000] ' *** NEED TO FIND TEXTBOX CONTROL NESTED IN A LISTBOX ITEM [/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] Next[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] End[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] Next[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] End[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Next[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE]
Any advice is greatly appreciated.
Thank you for your time,
Rob