views:

34

answers:

2

Hi,

My WPF combobox is populated with a different set of strings each click of a button. There are other controls on the window as well. The combobox is the 'first' (top) in the window, but the text doesn't get highlighted. When the user tabs through the controls, the text DOES get highlighted, but when it's the first on the window, it doesn't.

Maybe i need to force a highlight on the individual textbox control 'within' the combobox itself, but how would i do this? I couldnt seem to find the internal 'structure' of this control anywhere. Could anyone help here?

Jack

A: 

I'm not sure it's the best solution, but you can use FrameworkElement.FindName to access the child control -- it's guaranteed to be present in a combobox, because it's a key constituent part of the control.

That stated, is it not better to try and call .Focus() on the control? That is likely why when you tab, the highlight is provided.

Another option is to derive from ComboBox, and expose the child text box as a property allowing you to set it's selection, or add a method directly to the combobox to set it for you.

dhopton
+1  A: 

to get the TextBox of Combobox you can use

TextBox TxtBox = (TextBox)myCombo.Template.FindName("PART_EditableTextBox", myCombo); 
Kishore Kumar
During creation (ctor) of the combobox Template is null - so how would one get it during creation?
Sam