Ver Mensaje Individual
  #13  
Antiguo 20-09-2011
Avatar de roman
roman roman is offline
Moderador
 
Registrado: may 2003
Ubicación: Ciudad de México
Posts: 20.269
Reputación: 10
roman Es un diamante en brutoroman Es un diamante en brutoroman Es un diamante en bruto
A ver, prueba con esto:

Código Delphi [-]
procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
begin
  if GoingForward or GoingBackward then
  begin
    if StrToIntDef(StringGrid1.Cells[ACol, ARow], 0) = 0 then
    begin
      if GoingBackward then
        keybd_event(VK_SHIFT, 0, 0, 0);

      keybd_event(VK_TAB, 0, 0, 0);
      keybd_event(VK_TAB, 0, KEYEVENTF_KEYUP, 0);

      if GoingBackward then
        keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
    end;
  end;

  GoingForward := false;
  GoingBackward := false;
end;

procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  GoingForward := false;
  GoingBackward := false;

  if Key = VK_LEFT then
  begin
    keybd_event(VK_SHIFT, 0, 0, 0);
    keybd_event(VK_TAB, 0, 0, 0);
    keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
    keybd_event(VK_TAB, 0, KEYEVENTF_KEYUP, 0);

    Key := 0;
  end;

  if Key = VK_RIGHT then
  begin
    keybd_event(VK_TAB, 0, 0, 0);
    keybd_event(VK_TAB, 0, KEYEVENTF_KEYUP, 0);

    Key := 0;
  end;

  if Key in [VK_PRIOR, VK_UP] then
  begin
    GoingBackward := true;
  end;

  if Key in [VK_NEXT, VK_DOWN] then
  begin
    GoingForward := true;
  end;

  if Key = VK_TAB then
  begin
    if ssShift in Shift then
      GoingBackward := true
    else
      GoingForward := true;
  end;
end;

GoingBackward y GoingForward son variables boolenas delcaradas en el formulario.

En principio, con esto queda tal como quieres y se impide lo de la selección con el ratón (aunque no he hecho una prueba exhaustiva).

Aún así, el resultado puede ser confuso para el usuario, sobre todo con las teclas de avanzar o retroceder página, pues el "ciclado" puede dejarlos en un lugar para nada esperado.

¡Ah! Me olvidaba: en el ejemplo, para simplificar, la verificación de si la celda es editable se hace contra el contenido en sí de la celda (0 o 1).

// Saludos
Responder Con Cita