diff --git a/include/msksheet.cpp b/include/msksheet.cpp index 8ae13bf25..30305a89e 100755 --- a/include/msksheet.cpp +++ b/include/msksheet.cpp @@ -3051,13 +3051,19 @@ void TSheet_field::set_focus_cell(int riga, int colonna) void TSheet_field::set_focus_cell_id(long rec, short cid) { TSpreadsheet* s = (TSpreadsheet*)_ctl; - - //qui - - const int row = s->rec2row(rec); - const int col = s->cid2col(cid); - s->set_focus_cell(rec, col); + const int col = s->cid2col(cid); + const int row = s->rec2row(rec); + + // Controlla che la cella sia veramente visibile + int first_col, last_col, first_row, last_row; + xi_get_visible_columns(s->_obj, &first_col, &last_col); + xi_get_visible_rows(s->_obj, &first_row, &last_row); + + if (col >= first_col && col <= last_col && row >= first_row && row <= last_row) + s->set_focus_cell(row, col); + else + s->select(rec, col, true); } bool TSheet_field::on_key(KEY k)