Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   Bloquear filas en dbgrid (https://www.clubdelphi.com/foros/showthread.php?t=79636)

dfarias 24-07-2012 22:49:28

Bloquear filas en dbgrid
 
La consulta es la siguiente, al dezplegar en una cxgrid asociada a una query necesito que algunas de la filas mostradas no se puedan seleccionar (disabled o algo asi). Es posible esto? Muchas gracias.

Al González 25-07-2012 00:10:52

Hola.

Creo que podrías valerte del evento OnEditing de la vista cx. Si asignas False al parámetro Boolean AAllow, lograrás evitar que el usuario modifique el valor de la celda que está intentando editar, y por lo mismo te sirve para toda una fila.

Seguramente hay otros caminos, pero este es el que a bote pronto se me ocurre. :)

Agrego: Ahora que leo tu pregunta nuevamente, noto que escribiste seleccionar y no editar. En ese caso OnCanSelectRecord es un evento más apropiado, según se describe en la propia ayuda:

Cita:

TcxCustomGridTableView.OnCanSelectRecord

Occurs before selecting a grid record.

Código Delphi [-]
type
  TcxGridCanSelectRecordEvent = procedure(Sender: TcxCustomGridTableView;
    ARecord: TcxCustomGridRecord; var AAllow: Boolean) of object;

property OnCanSelectRecord: TcxGridCanSelectRecordEvent;

Description

The OnCanSelectRecord event is fired only when the view’s OptionsSelection.MultiSelect property is set to True. Use this event to control record selection. The Sender parameter identifies the affected view and the ARecord parameter specifies the record to be selected. To enable record selection, set the AAllow parameter to True. This adds the current record to the collection of selected records.

Indexed access to selected records in default loading mode (when the GridMode property is set to False) is provided by the view’s Controller.SelectedRecords property. When GridMode is applied, see the view’s DataController.GetSelectedBookmark function to obtain selected records.

If the OnCanSelectRecord event handler sets AAllow to False, records will not be selected. However, OnCanSelectRecord does not allow you to prevent record focusing.

The following example disables selection of a record if its tvItemsSTATUS field denotes the ‘Fixed’ string. The value displayed by the item is determined by the indexed DisplayTexts property.

Código Delphi [-]
procedure TForm1.tvItemsCanSelectRecord(
  Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
  var AAllow: Boolean);
begin
  if ARecord.DisplayTexts[tvItemsSTATUS.Index] = 'Fixed' then

    AAllow := False;
end;


dfarias 25-07-2012 10:48:15

Muchas gracias, funciona correctamente.


La franja horaria es GMT +2. Ahora son las 18:06:05.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi