Hi There.
In a richviewedit, if there is a Delphi control such as a TEdit and the user directly selects the TEdit using the mouse in order to perform some input, the CurItemNo does not get updated. It does if the user selects other item types but it appears that TControls intercede . Is there a way to get the index of the item the user has selected and is working in if it is a TControl?
Getting item index of selected control
-
- Posts: 5
- Joined: Wed Mar 31, 2021 8:56 pm
-
- Site Admin
- Posts: 17842
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Getting item index of selected control
The simplest solution is selecting the control on clicking on it: process OnMouseDown of controls, and call RichViewEdit.SelectControl() in it.
See the example in viewtopic.php?t=157 (how to resize and drag&drop controls in the editor).
See the example in viewtopic.php?t=157 (how to resize and drag&drop controls in the editor).
-
- Site Admin
- Posts: 17842
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Getting item index of selected control
If you want to find the location of the control, you can use this function:
On input, RVData must be TRichView.RVData.
On output, RVData is a document containing the control (one of: TRichView.RVData, cell, or RVData of cell inplace editor), or nil if the control is not found.
Here is how you can use this function to select this control (i.e., doing the same work as SelectControl):
Code: Select all
procedure FindControlLocation(var RVData: TCustomRVData; out ItemNo: Integer);
var
table: TRVTableItemInfo;
r,c: Integer;
begin
ItemNo := RVData.FindControlItemNo(TControl(Sender));
if ItemNo<0 then
begin
RVData := nil;
exit;
end;
if RVData.GetItem(ItemNo) is TRVTableItemInfo then
begin
table := TRVTableItemInfo(RVData.GetItem(ItemNo));
table.GetCellWhichOwnsControl(TControl(Sender), r, c, ItemNo);
RVData := table.Cells[r,c].GetRVData;
FindControlLocation(RVData, ItemNo);
end;
end;
On output, RVData is a document containing the control (one of: TRichView.RVData, cell, or RVData of cell inplace editor), or nil if the control is not found.
Here is how you can use this function to select this control (i.e., doing the same work as SelectControl):
Code: Select all
var
RVData: TCustomRVData;
ItemNo : Integer;
begin
RVData := RichViewEdit1.RVData;
FindControlLocation(RVData, ItemNo);
if RVData = nil then
exitl
RVData := RVData.Edit;
TCustomRVFormattedData(RVData).SetSelectionBounds(ItemNo, 0, ItemNo, 1); // or (ItemNo, 1, ItemNo, 1) to move the caret after the control
end;