Set Focus to a cell in ALV on action performed outside ALV

Hi All,
In my application i have created a dynamic ALV using technical structures.
I have few fixed columns and few scrollable columns.
The scrollable columns represents dates. The caption of the ALV headers are set later with the dates.
I have a date navigator control. On choosing a date, the headers of date columns changes.
Table layout is fixed with 4 displayed scrollable columns displayed each time.
Issue:
When i use horizontal scroll on ALV and then navigate on a date, then the ALV headers are updated. But the scroll position is not changed. I would want to focus on the first date column.
I tried 2 options to set focus. But both dont seem to work.
Could you provide me some suggestions?
Option 1:
  CALL METHOD lo_view->if_wd_view_controller~request_focus
    EXPORTING
      context_element = lo_el_time_ps            " i get the element reference for the right index )
      attribute       = lv_attribute_name            "first date column name (technical name)
Option 2:
lo_interfacecontroller = wd_this->wd_cpifc_alv_usage1( ).
lo_interfacecontroller->set_focus(
                                  index = lv_index                       " i get the element reference for the right index )
                                 column = lv_attribute_name ).   "first date column name (technical name)
Regards,
Rekha

hi Carles Costa,
i think your issue is type of Purchase document. if it is Item type then matrix (38) and column(1) is itemcode,
if service type then matrix(39) and column 1 is Description.
this code oMatrix.Columns.Item("1").Cells.Item(pVal.Row).Click() or oMatrix.Columns.Item("1").Cells.Item(pVal.Row).Click(BoCellClickType.ct_Regular) is correct.
hope this help you.
thanks
H2

Similar Messages

  • How to set focus to a cell

    Hi everybody,
    How can i set focus to a cell?
    In the Purchase Matrix:
    oMatrix.Columns.Item("1").Cells.Item(pVal.Row).Click()
    But This set focus to column 3  (Item description. Not 1). Why?
    Thanks
    Carles
    Edited by: Carles Costa on Mar 4, 2011 10:57 AM

    hi Carles Costa,
    i think your issue is type of Purchase document. if it is Item type then matrix (38) and column(1) is itemcode,
    if service type then matrix(39) and column 1 is Description.
    this code oMatrix.Columns.Item("1").Cells.Item(pVal.Row).Click() or oMatrix.Columns.Item("1").Cells.Item(pVal.Row).Click(BoCellClickType.ct_Regular) is correct.
    hope this help you.
    thanks
    H2

  • Problem of set focus on the cell during the validation.

    I am having a table with 5 columns.
    I can change the value of the 2nd cell in 2 ways.
    one by 1. editing the 2nd cell
    or by 2. clicking the button avilable in the 1st cell.(the button editor will set the value to the 2nd cell of selected row)
    In both cases, i have to validate the value in the 2nd cell.
    If the value is not meeting some criteria, i am pop uping a msg box, contain approprite message.
    and the cursor should be focused on the 2nd cell until the value will be corrected.
    i done for the case 1.
    but for the case 2, i couldn't keep the cursor on the 2nd cell when the value got changed by the button editor of cell 1, and if the value is wrong
    The 1st cell 2nd cell are having it own Renderer and Editor
    even i tried a lot, but i not yet achieved it.
    pls. guide me to get a perfect result.

    Thnks for u'r reply.
    the 1st part what i mentioned is done by the same way in those example by the sun site only.
    But in the 2nd part, when i set the value to text field by the button editor,
    the editor of the textField(2nd cell), is not got called.
    If i made to call editor also, i am unable to keep the cursor on 2nd cell

  • How to set Focus on a Cell in a Table

    I have a column for which i set the table editor in the following way :
    DateTextField contractStarts = new DateTextField();
    itemTable.getColumnModel().getColumn(9).setCellEditor(new DefaultCellEditor(contractStarts);
    When the focus is brought to a cell in 9th column thru tab key I want the cursor displayed and invariably invoking the cell editor without clicking the cell.
    If i don't click on the cell the cell editor (contractStarts) implementation does not seem to work or otherwise does very well. Since normally a user would manoeuvre using tab key.
    Can this be done. I am searching for possible clues to this.
    Regards
    Shomal

    OK well I tried your example again and it does work in my Chrome and Firefox browser. IE10 still won't let me type into the fields.
    I borrowed some of your code and changed your input to fit with mine.
        if (typeof oItem.getCells()[1].$().find('input').selectionStart === "number") {
    oItem.getCells()[1].$().find('input').selectionStart =
         oItem.getCells()[1].$().find('input').selectionEnd =
      oItem.getCells()[1].$().find('input').value.length;
        } else if (typeof oItem.getCells()[1].$().find('input').createTextRange !== "undefined") {
    oItem.getCells()[1].$().find('input').focus();
    var range = oItem.getCells()[1].$().find('input').createTextRange();
    range.collapse(false);
    range.select();
    In debugger when I evaluate:
    oItem.getCells()[1].$().find('input').selectionStart
    it is undefined.

  • Set focus on particular cell in a JTable when using TableModel.

    I want to implement validation in my table cells. I the value does not satisfy certain condition then the focus should remain on the same cell and the user should be asked to enter valid value.
    I am using TableModel and i have tried implementing validation in the setValueAt() method some thing like this.
    setValueAt method of my table model.
    public void setValueAt(Object value, int row, int col){
    if(datalist.size()>row){
    OutboundFieldMappingObj obj=(OutboundFieldMappingObj)datalist.get(row);
    String str=null;
    switch (col){
    case 0:
    str=Validator.getValidNumber((String)value,1,999999999L);
    obj.setFiledName(str);
    break;
    case 1:
    str=Validator.getValidString((String)value,128,false);
    obj.setFiledClass(str);
    break;
    case 2:
    obj.setSource((String)value);
    break;
    fireTableCellUpdated(row, col);
    But this doesn't solve the issue. In this case after entering the value when i click on some other cell then it shows me a message stating that the value is invalid but it doesn't takes the focus back to same cell. The focus is shifted to the cell where i have clicked.
    Please help me out in resolving the issue.
    I have added the code of my validator class at the bottom if any one needs to have a look at it.
    Thanks
    Validator class
    public class Validator {
    public Validator() {
    public static String getValidString(String val, int max, boolean upper) {
    if (val == null || val.equals("")) {
    showErrorMsg("The cell can not be left blank");
    return " ";
    if (val.length() > max) {
    val = val.substring(0, max);
    showErrorMsg("String value to long. Truncated to " + max +" characters.");
    if (upper) {
    val = val.toUpperCase();
    return val;
    public static String getValidNullableString(String val, int max, boolean upper) {
    if (val == null) {
    return null;
    if (val.length() > max) {
    val = val.substring(0, max);
    showErrorMsg("String value to long. Truncated to " + max +" characters.");
    if (upper) {
    val = val.toUpperCase();
    return val;
    public static String getValidNumber(String number, int min, long max) {
    try {
    long num = Long.parseLong(number);
    if (num < min) {
    showErrorMsg("Number less than mininum value of " + min + ".");
    return "" + min;
    if (num > max) {
    showErrorMsg("Number greater than maximum value of " + max +".");
    return "" + max;
    return number;
    } catch (Exception x) {
    showErrorMsg("Invalid Entry. Number Expected.");
    return "0";
    // return "";
    public static boolean getValidNumber(String number) {
    try {
    Integer.parseInt(number);
    return true;
    } catch (Exception x) {
    showErrorMsg("Invalid Entry. Number Expected.");
    return false;
    // return "";
    public static void showErrorMsg(String message) {
    JOptionPane.showMessageDialog(new java.awt.Frame(), message,
    "Invalid Value!",
    JOptionPane.ERROR_MESSAGE);
    public static boolean validString(String str) {
    if (str != null && str.length() > 0) {
    return true;
    return false;
    }

    You need to create a custom editor. Something like this:
    http://forums.sun.com/thread.jspa?forumID=57&threadID=642364
    If you need further help then you need to create a [Short, Self Contained, Compilable and Executable, Example Program (SSCCE)|http://homepage1.nifty.com/algafield/sscce.html], that demonstrates the incorrect behaviour.
    Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.

  • Set focus to a cell - not editable

    Hello, i have an item renderer that consists of a combobox in a datagrid which has roughly 10 columns.  Columns 2 (combobox), 5 (regular text fields), and 7 (regular text fields) are editable.  So when I tab - i want it to goto column 2, then 5, then 7, then 2 again.  However, when i set "editedItemPosition" to "2", the combobox renderer disappears and it becomes a textfield.  How do i make it so the combobox within the renderer is in focus?
    Thanks in advance.

    I tried that.  And it still doesn't work.
    Not sure if it matters, but the advanceddatagridcolumn editable property is set to false.

  • How to set focus on a input field in a selected row of a table?

    In a previous discussion (http://scn.sap.com/thread/3564789) I asked how to access an input (sap.m.Input) field of a selected row in a table. In the answer that was supplied I was shown how to get the items of the table. Then using the selected index to get the selected item get the cells. Then I could set editable on the proper cell(s). This worked fine.
    Now I need to set the focus on one of the fields. I tried something like this:
                var oNewLink = table.getSelectedItem();
                var oNewLinkName = oNewLink.getCells()[1];
                oNewLinkName.focus();
    But this doesn't seem to work.
    I have searched through other discussions and have seen this technique for putting focus on a field if you have its ID:
    sap.ui.getCore().byId(id_of_the_input_field).$().focus();
    In my case though I do not have an ID since the row and its cells are generated. How can I set focus on the cell of a certain row in a table?

    Hello Venkatesh. Yes that code does work. First I tried it on a table cell that was already rendered and it did work. The next time I tried it on a table row that was being added and it did not work there. So I added an on after rendering function for the table and added that code there. That did not work until I added a delay (timeout) to do a context switch before calling the focus and that worked.
    Once last thing though sometimes when I call focus on an input field (actually in a table row cell) if the field has text in it already the flashing cursor is at the beginning of the text and other times it is at the end of the text (which is the desired way). It depends on where I click in the row. Is there anyway to make sure the flashing cursor is at the end of the text when the focus is applied to a field that contains text?

  • Set focus on cell in ATS Table

    Hi Friends,
    I try to set the focus on a field in a if_fpm_guibb_list.
    I use Methode request_focus_on_cell in if_fpm_list_ats_ext_ctrl.
    And I set lead Index to new line and set selected_line _changes to 'X'.
    When I look in the table what contain the new position, it contains the Data for the new position.
    But the cursor is not jumping to the Cell.
    Is there something in addition what I have to do?
    Thanks in advance
    Joerg.

    Hi Joerg,
    I'm facing exactly the same problem. I want to set the focus to a cell in an FPM_LIST_UIBB and REQUEST_FOCUS_ON_CELL in method GET_DATA looked promising, but the cursor is not set to the field.
    Only the lead index of the table is changed to the correct line if I set parameter CV_LEAD_INDEX in method GET_DATA.
    Did you find a solution?
    Thanks,
    Karsten

  • Refresh ALV & set focus

    Hi,
       I have a refresh option on my screen. It will bring latest data from database. After displaying data in ALV and scrolling down (lets assume scrolled down 10 records). if I select refresh, I am reloading data to ALV. But focus is going to first record. I have again scrool down to 11th record to check the data. How I can set focus to 11th record after repopulating data on ALV. I am using classes for ALV.
    I will appriciate any inputs.
    Regards,
    Venkat.

    Hi,
    Check this example of using the method set_current_cell_via_id.
        DATA: ROWNO TYPE LVC_S_ROID.
        ROWNO-ROW_ID = 25.
    Set the focus on the row number 25.
        CALL METHOD <b>grid1->set_current_cell_via_id</b>
          EXPORTING
            IS_ROW_NO    = rowno.
    Hope this helps..
    THanks,
    Naren

  • URGENT!!! How to set focus to a required cell in JTable with ENTER

    Hello everybody,
    I want to change the focus to the cell(identified by row, column) while pressing ENTER. Pleas help me on this issue.

    Hello Venkatesh. Yes that code does work. First I tried it on a table cell that was already rendered and it did work. The next time I tried it on a table row that was being added and it did not work there. So I added an on after rendering function for the table and added that code there. That did not work until I added a delay (timeout) to do a context switch before calling the focus and that worked.
    Once last thing though sometimes when I call focus on an input field (actually in a table row cell) if the field has text in it already the flashing cursor is at the beginning of the text and other times it is at the end of the text (which is the desired way). It depends on where I click in the row. Is there anyway to make sure the flashing cursor is at the end of the text when the focus is applied to a field that contains text?

  • How do I set background color of cell using JTable?

    Hello all!
    I have a question on the use of JTables. I am using a JDialog consisting of a JTable and a number of buttons to insert and to select OK or cancel. Everything is working perfectly, but I now must add editing capabilities to prevent invalid data being used in a SQL query to update or insert rows.
    So far I can't figure out how to get at a cell to set the background to red if the user inputs a Date incorrectly. Upon setValueAt(), I take this value and check for standard format errors. I hope to someday convert the column altogether to a Data object (or some form since Date is deprecated):-) For the time being, I know when an error occurs, but don't have the foggiest idea how to render the error (set backround to red).
    I need to give you more info too, since the way we do things is to make it as complicated as possible for job security and to impress the newbies(or scare them back to COBOL). When I setValueAt(), I have a DefaultDataElement object that houses everything for a given column in DB2. It has column name, length, data type, is it new, original value, current value, etc. If one doesn't exist, then I create one. After all said and done, I parse thru these elements and build my update/insert query and then execute the query.
    The event starts as soon as the user presses the OK button. But, if a date cell contains an invalid date, I need to halt processing (which I've done) and somehow let the user know which cell was invalid. We consider our users dumb (they really aren't, but the assumption is made), so I can't just say "error occurred in table. Verify data and try again". That won't work:-) Gotta be able to show them what cell is bad.
    Any ideas?
    Thanks,
    Patrick

    I finally figured it out. I was always close, but it wasn't until late yesterday that the light bulb came on. I was setting the background on the component in getTableCellEditorComponent() by grabbing the super.getTableCellEditorComponent(). The problem was all this was located in an editor, not renderer. So what happened was as I edited the cell the check would be performed then, not as focus was lost. When focus was lost, the red background went back to normal.
    I ripped the code out and made a custom renderer and got closer. Problem was the whole column had a red background. Even specifying the row and column in getTableCellRendererComponent didn't apply just to that cell. That row and column is only for obtaining the data in the cell, but anything affecting the component will affect the column, since I added the renderer to my TableColumn:-) I need to add error logic to my model and when an error occurs, set a boolean flag in a 2 dimensional array where the row and column is used to get to it from the renderer.
    Thanks for the help!!!

  • Problem in setting focus in JTable

    Hi,
    In my application I am using JTable with a customized table model. The table has two columns. First column has jcombobox as its editor and the second column has the customized editor developed by me. This particular table appears in a wizard. When this wizard page (which contains the above JTable) is shown I set the keyboard focus on the JTable using JTable's requestFocus() method (I even tried with grabFocus()method but got the same result). But the focus does not appear on the JTable. Even none of the cells get the focus. Also no matter how many time I press tab key the focus does not shift to the next component in the page which happens to be a JButton. I have set the next focussable element for the JTable as that JButton. When I manually put the focus on one of the cells by clicking on it and then if I press either arrow key or tab key the focus is lost and it does not go either on the next cell or the JButton.
    If anybody can shed some light on what exactly needs to be done to give proper keyboard navigation for JTable please let me know.
    Regards
    Atul

    Hi Atul,
    I suspect your problem is with your cell renderer. The DefaultTableCellRenderer class has code in the getTableCellRendererComponent method that provides the visual indication as to which cell has the focus. You will want to do something similar in your JPanel-subclassed renderer - perhaps change the border or the background color to indicate whether a cell is selected or not.
    Note also that there is a difference between a cell that has "isSelected" set to true, which indicates that the cell is part of the current selection, and a cell that has "hasFocus" set to true, which indicates that the cell is the last one to be clicked on. Actually, it seems to be a bit more complicated than that, but that's at least part of what "hasFocus" indicates. A cell can be selected and not have the focus, and a cell can have the focus but not be selected. You may want to setup your renderer to clearly indicate which of these states are set and then run your app and play with the table selection to get a feel for how it works.
    Hope that helps.
    - Tyler

  • Setting focus on a component from backing bean

    Is there an easy way to set focus in a specific component on the jspx from a method in the backing bean? (other than javaScript coding...)

    Hi,
    did you take a look at
    About control the cursor position in a JSF web page
    It contains some links to other weblogs. The links are helpfull. Maybe you'll be able to find your solution there......
    Good luck
    Luc Bors

  • How to set focus on the title of JTabbedPane

    I have created a JTabbedPane and added three JPanels to it. They are titled, say "Panel 1", "Panel 2" and "Panel 3". And each of them contains buttons and text areas. Since this app is for physically disabled users, it must provide navigation through these three tabs with keyboard operations only (i.e. without mouse clicks).
    When the title "Panel 1" gets focused, users can go to "Panel 2" by the right arrow key. When Panel 2 is brought up, however, the title "Panel 2" does not get focused. Instead the first button inside panel 2 is focused. In order for users to navigate to 'Panel 3" by the arrow key, the title "Panel 2" has to be focused. How do I set focus on the tab title?
    I have tried 'requestFocus()' on Panel 2, but it does not work. Please help me with this issue. Thanks in advance.

    I'd be quite interested to know if this can be doen as well so I thought I'd post this message to move it to the top of the board.
    Thanks.

  • How to set focus on a custom PO Item screen field when in error?

    Hi All,
    I have an interesting situation that i'm wondering if others have solved.  We have extended the PO item table (EKPO) by adding two new fields.  We then have implemented two BAdI's:  ME_GUI_PO_CUST and ME_PROCESS_PO_CUST to add them to the ME21N/ME22N/ME23N screens and logic to do some validation, via these respective BAdI's mentioned.  Everything works perfectly - with one small issue.  When we are doing some validation via a method on the ME_PROCESS_PO_CUST - and "invalidate" the field (and throw an error) when it is in error - I also want to be able to "set focus" on the field in question (basically: go to the particular tab on the ME* screen and highlight the field).  I have tried using SET CURSOR FIELD *****  within this BAdI (ME_PROCESS_PO_CUST) - but doesn't seem to work.  Has anyone tried to do this and have come up with a solution?  Would be much appreciative if you shared it!!!  Thanks much.
    Cheers,
    Matt
    ERP version that we have is:  ECC 6.0

    Just have a look at oss note 310154 - ME21N/ME51N: Customer-specific check, generating error log.
    In short:
    Add your error messages in EXIT_SAPMM06E_012 (using specific macros).
    Sample code (provided in Oss note) :
      loop at tekpo where knttp eq 'X'.
        loop at tekkn where ebeln eq tekpo-ebeln and
                            ebelp eq tekpo-ebelp and
                            kostl eq space.
          if not tekkn-id is initial.
            mmpur_business_obj_id tekkn-id.
            mmpur_metafield MMMFD_ACCOUNTINGS.
          endif.
          mmpur_message_forced 'E' 'ZE' '777' '' '' '' ''.
        endloop.
      endloop.

Maybe you are looking for

  • Is my iphone4 factory unlocked and will it work after i restore it??

    i bought an iphone4 from the US,i am using it in India now. the retailer said it is a factory unlocked iphone. i did not jailbreak or unlock it , i even upgraded the phone to 4.3.3. and it is working fine. will it work if i restore it and is it facto

  • Calling two smartforms in one Abap program

    Hi ABAPers, Can anybody know how to call 2 smartforms in 1 abap program?actually i used the FM SSF_FUNCTION_MODULE_NAME...and two smart forms are called...but my main problem is...the first smartforms is called and the print dialog box appeared...onc

  • Representing in a collection

    I have some data in a table like the following date1 date2 date3 id1 10 12 13 id2 11 12 9 id3 7 9 4 I need to store this in a way so that a value can be easily retrieved by calling something like get(id1,date3), which should return 13. I am currently

  • Extra Field gone after reopening a saved Report

    Hi all, Maybe it is a stupid question but when i have builded a report with the wizzard and i add a extra Field and i save the report as a rdf. The next time i open the saved report the extra Field is gone. Does anybody know why? Thanks in advance, D

  • Connect By with composite Key

    Hello I have a table more or less like this ID - CONTINENT- COUNTRY-CITY 1 ASIA 2 ASIA CHINA 3 ASIA CHINA BEIJING 4 ASIA CHINA XANGAI 5 ASIA JAPAN 6 ASIA JAPAN TOKIO 7 EUROPE 8 EUROPE GERMANY Altough I have a sequencial primary key, that key os not u