Give focus to grid in container

I have a form inside a window which contains an input element and a container control to which a grid has been attached.

var module_windows = new dhtmlXWindows();

var global_search_window = module_windows.createWindow(“global_search_window”, 1, 1, 650, 565);

var global_search_form = global_search_window.attachForm([
{type:“input”, name:“search_string”, width:350 }
{type:“container”, name:“global_search_results_container”}
]);

var global_search_results_grid = new dhtmlXGridObject(global_search_form.getContainer(“global_search_results_container”));

How can I change the focus from the input element to the grid? I have tried the following commands without success (together or separately):

global_search_results_grid.selectRow(0);
global_search_results_grid.setActive(true);
global_search_form.setItemFocus(“global_search_results_container”);
jQuery(global_search_results_grid).focus();

Thanks.

global_search_results_grid.setActive(true);

This one must make the grid active, so it will respond to hotkeys and so on.
Does it not work in your case? Or do you need some other effect except hotkeys?

Stanislav,

Oddly, it does not work as expected.

Strangely, what DOES work is if I add a button to the form, and first set the focus to the button, then it works.

If I have this:

var global_search_form = global_search_window.attachForm([
	{type:"input", name:"search_string", width:350 },
	{type:"button", name:"search_button", value:"Search"}
	{type:"container", name:"global_search_results_container"}
]);

And I do this:

global_search_form.setItemFocus("search_button");
global_search_results_grid.setActive(true);
global_search_results_grid.selectRow(0);

It works as expected and the grid becomes focused and responds to keyboard input. The problem only happens when the text field has the focus.

If you are calling this logic from inside of oncklick event handler of some button, try to change code like next

setTimeout(function(){ global_search_results_grid.setActive(true); global_search_results_grid.selectRow(0); }, 1);

It will ensure that focus operation will be executed after full click event processing