Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to 'get at' the WPF combobox PART_EditableTextbox because combobox not getting highlighted?

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

like image 961
user281794 Avatar asked Aug 10 '10 15:08

user281794


2 Answers

to get the TextBox of Combobox you can use

TextBox TxtBox = (TextBox)myCombo.Template.FindName("PART_EditableTextBox", myCombo); 
like image 131
Kishore Kumar Avatar answered Oct 22 '22 15:10

Kishore Kumar


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.

like image 1
Dominic Hopton Avatar answered Oct 22 '22 15:10

Dominic Hopton