Search code examples
gwtsmartgwt

Firing ListGrid selection item on GWT


When the user clicks a button, I want to fire the ListGrid Selection event. I called "resultControl.resultGrid.selectRecord(0);" but it didn't work.


Solution

  • From your initial question and your comment, I understand that you want to simulate a selection event in your ListGrid, through a button. Assuming that I understand well, and you are only interested in one record selection (the first one), all you have to do is the following:

        final ListGrid listGrid = new ListGrid();
        //Initialize your listgrid's data etc.
    
        listGrid.addSelectionChangedHandler(new SelectionChangedHandler() {
    
            @Override
            public void onSelectionChanged(SelectionEvent event) {
                SC.say("here my code");
            }
        });
    
    
        IButton button = new IButton("Select");
        button.addClickHandler(new ClickHandler() {
    
            @Override
            public void onClick(ClickEvent event) {
                listGrid.selectRecord(0);
    
            }
        });
    

    A last note, System.out or System.err won't produce anything when your application runs in production mode. Use a suitable logging solution or the SC.say(), if you want to provide the user with a message, instead.