cxGrid 6 FocusedRecordChanged want to know if FocusedItemChanged
I have the GotToNextCellOnEnter and the FocuscellOnCycle properties set to true. When I press enter on the last cell the FocusedRecordChanged event fires and then the FocusedItemChanged event fires. Is there a way of detecting that the FocusedItemChanged event is due to fire from within the FocusRecordChanged event. I am trying to use these events sto开发者_运维技巧p the user from focusing on specific cells. I want to ignore the FocusedRecordChanged event if the FocusedItemChanged event is going to fire just after it. Ideally what I want is a FocusedCellChanged event but there is not one of these.
Thanks
As stated in the help for the ExpressQuantumGrid Suite 6 the OnFocusedRecordChanged
Occurs after focus is moved to a different record.
and the OnFocusedItemChanged
Occurs when focus is changed to a different View item.
where an Item is a column.
That means that (with your current configuration, i.e., GoToNextCellOnEnter and FocusCellOnCycle set to true) everytime you leave pressing the Enter key the last column of a record both events will always fire since you are moving to the first item of the next record.
EDIT: In the case of leaving with the Down key it is absolutely normal that the OnFocusedItem does not fire since it only does so if you change the column. You could try to capture the key used to leave the cell. My guess is that the OnKeyDown event occurs before any of these 2 events.
If I understood your needs right, you will need to treat the last column differently in your event handlers.
Hope that helps,
Best regards
I would suggest that you disable both options and implement this logic yourself. Here is the default implementation, you should just change it so that it meet your custom logic:
procedure TForm1.cxGrid1DBTableView1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
ASite: TcxGridSite;
begin
if Key = VK_RETURN then
begin
ASite := TcxGridSite(Sender);
FocusNextCell(TcxGridTableView(ASite.GridView));
Key := 0;
end;
end;
procedure TForm1.cxGrid1DBTableView1EditKeyDown(
Sender: TcxCustomGridTableView; AItem: TcxCustomGridTableItem;
AEdit: TcxCustomEdit; var Key: Word; Shift: TShiftState);
begin
if Key = VK_RETURN then
begin
FocusNextCell(TcxGridTableView(Sender));
Key := 0;
end;
end;
procedure TForm1.FocusNextCell(AView: TcxGridTableView);
var
AColumn: TcxGridColumn;
begin
AColumn := AView.Controller.FocusedColumn;
if AView.Controller.FocusedRow.IsData then
begin
if AColumn.VisibleIndex < AView.VisibleColumnCount - 1 then
AView.VisibleColumns[AColumn.VisibleIndex + 1].Focused := True
else
if AView.Controller.FocusNextRecord(AView.Controller.FocusedRecordIndex, True, True, False, False) and AView.Controller.FocusedRecord.HasCells then
AView.VisibleColumns[0].Focused := True;
end
else
if AView.Controller.FocusNextRecord(AView.Controller.FocusedRecordIndex, True, True, False, False) and AView.Controller.FocusedRecord.HasCells then
AView.VisibleColumns[0].Focused := True;
AView.Controller.EditingController.ShowEdit();
end;
精彩评论