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

myTextBox[3].Focus()

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..
thanks

Member Avatar for Unhnd_Exception

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;
tb_tofocus.Focus();

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

myTextBox[3].Focus()

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.
thanks

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.