hi there
im using visual c#
i have a list box and it contains about 50 textboxes arranged in a tabular fashion.
the textboxes are represented by an array myTextBox[50].

what i wanted to do is to focus a particular textbox in the listbox.
so what i did is


to select the fourth textbox on the listbox.
but it didnt work...the textbox was not focused..
please help
and i have set the tabnaviagtion of textbox to Local too..

6 Years
Discussion Span
Last Post by Diamonddrake

Didn't know you could get a textbox in a listbox.

try myTextBox[3].Select();


It should work, assuming that your array is of type TextBox or Control.
you could try something like

Control tb_tofocus = myTextBox[3] as Control;

But not seeing the code is hard to tell whats going on, because in theory it should work as is.


actually i guess the problem is that all the textboxes are inside a ListBox.
However i have made an array of these textboxes.
Now each time i press the TAB key inside the ListBox, actually each textboxes on the listbox should get a focus..however at first the section behind the textbox gets focused and then again on pressing TAB key the textbox gets focus.
this means i have to press TAB key twice while going from one textbox to another textbox inside that listbox.
so what i thought is i would get the index of the selection on the listbox which gets selected for the first time i press TAB key and then focus the corresponding textbox on its top..but it didnt work.

however i also tried this


directly but also it did not work.
also the above solution you gave did not work in this case.

please also note that i am using c# wpf and the Focus() method for textboxes is working in normal cases where the textbox is not inside the listbox.

also in the xaml code i have set Navigation of listbox to local.


I wasn't really even aware you could put a textbox inside of a listbox. I'm not sure if the listboxitem object has a tabstop property, but if it does you could try setting it to false so that the tabs would skip the section behind the textbox. But that's just a guess.

I don't play much with WPF. I hope that this suggestion works out for you.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.