Is there a way to tell if a treeview node is currently in edit mode?
I'm using the KeyUp event to determine if the delete key was hit - I only want to fire off my 'do you really want to delete this' code if the user is NOT editing.
This project is using Delphi 2010.
You can ask the TTreeView.IsEditing property. From the reference:
Indicates whether a node is currently being edited by the user.
IsEditing returns true if any node label in the tree view is being
edited.
Related
I'm a newbie to Delphi and coding itself and have an issue which I can't solve.
I have to create a Treelist based on values from a Database which I did in the design field, here is an example on how it looks:
. Now it needs to be able to insert a new row after giving it a description (which is labeled as 'bez') while running.
The most obvious way to do that in my mind is to right click on a parent field and be able to add a new child field, how can I achieve that?
Also at the end of a parent tree I need it to be able to open a script/file, is that possible too?
With delphi, i have a dbgrid. I want when user has filled the row and posted it, the line of grid is readonly
Do you have any suggestion ?
thank you
Long time since last Delphi dev but I would have aborted an OnBeforeEdit event if there is data in the buffer.
My two cents
I suggest to keep a list with all rows (All data or just the primary key or the row ID) already updated by the user. Before allowing an update, you check the list.
To prevent accidental / unwanted edits you can turn off the AutoEdit property of the TDataSource providing data to the DBGrid. Then be sure any controls like a DBNavigator do not have edit enabled.
From the Delphi Help:
Description
Specifies whether the data source should call the Edit method automatically.
AutoEdit is true by default. If AutoEdit is true, then when a user attempts to modify the data displayed by the control, the data source calls the underlying dataset's Edit method.
Set AutoEdit to false to protect data from unintentional modification. Even if AutoEdit is false, an application can explicitly call a dataset's Edit method to allow data modification.
I have a no of DBCheckboxes on a form I want to be able to check/uncheck one or more of these programmatically depending upon whether the user checks /unchecks a different DBCheckbox also on the same form I cant seem to be able to do this using the onclick event
I can't seem to be able to do this using the onclick event
The reason is the tight coupling between the state of db-aware components such as TDBCheckBox and that of the dataset they are connected to. If you attempt to interfere with this by trying to set the gui state of the component (e.g. the Checked state of a DBCheckBox), the db-aware model these components all work to will fight you every inch of the way, because you are effectively trying to subvert the mechanism by which the gui state of the component is kept in sync with the value in the corresponding dataset field.
So, as Val Marinov correctly said, the thing you need to do is to manipulate the field value instead, as in the following:
if MyDataSet.FieldByName('OtherBooleanField').AsBoolean <> RequirdValue then begin
if not (MyDataSet.State.State in [dsInsert, dsEdit]) then
MyDataSet.Edit;
MyDataSet.FieldByName('OtherBooleanField').AsBoolean := RequiredValue;
It's up to you what trigger you respond to, to execute code like this.
on clickevent of check box set the Field of appropriate checkbox
In the OnChange event of the fields change the values of the other fields that need to change.
Everyone probably knows what I mean, but to clarify the control would need to:
Fire an event when user edits the text. The event would provide a SuggestionList: TStrings which you could fill with matches/suggestions.
if the SuggestionList is not empty a drop down should appear.
Unlike combo, the control should not attempt to automatically select/auto complete or otherwise affect the editing.
So, is there a Delphi edit/combo control that works like that ?
Use the autocompletion feature built in to all Windows edit controls.
First, fill your TStrings object however you want. Then use GetOleStrings to create a TStringsAdapter to wrap it. (The adapter does not claim ownership of the TStrings object, so you must make sure you don't destroy it while the adapter is still live.) The adapter gives you an IStrings interface, which you'll need because the autocompletion feature requires an IEnumString interface to provide the completion matches. Call _NewEnum for that.
Next, call CoCreateInstance to create an IAutoComplete object. Call its Init method to associate it with the window handle of your edit control. If you're using a combo box, then send it a cbem_GetEditControl message to find the underlying edit window.
You can stop at that point and autocompletion should work automatically. You can disable autocompletion if you want, or you can set any number of autocompletion options.
You say you don't want autocompletion, but in the OS terminology, I think what you really don't want is called auto append, where the remainder of the string is entered into the edit box automatically as the user types, but selected so that further typing will overwrite it, and the user needs to delete the excess text if the desired value is shorter than one of the matches.
There is also auto suggest, which displays a drop-down list of suggestions.
You can enable either or both options. You don't need to filter the list of suggestions yourself; the autocomplete object filters the IEnumString list by itself.
You can use standard TComboBox and faststrings library (for stringMatches() function).
procedure TForm1.cbChange(Sender: TObject);
var
s:Integer;
tmpstr:string;
begin
//suggestions: tstringlist
cb.AutoComplete:=false;
tmpstr:=cb.Text;
cb.Items.Clear;
for s:=0 to suggestions.Count - 1 do
if StringMatches(suggestions[s],cb.Text+'*') then
cb.Items.Add(suggestions[s]);
cb.DroppedDown:=(cb.Items.Count<>0) and (Length(cb.Text)<>0);
cb.Text:=tmpstr;
cb.SelStart:=Length(cb.Text)
end;
If you just want to show a file or url list:
SHAutoComplete(GetWindow(eb_MyComboBox->Handle, GW_CHILD), SHACF_AUTOSUGGEST_FORCE_ON | SHACF_FILESYS_DIRS);
I first implemented this feature like Rob described it in his answer. Later I saw that TComboBoxEx has the property AutoCompleteOptions where I set acoAutoSuggest to True and acoAutoAppend to False. The ComboBox now filters its item list when doing some entry and shows the matching items.
I'm using RAD Studio 10 Seattle and XE2 but don't know if this feature is available in older versions.
To the last bit of your question: "So, is there a Delphi edit/combo control that works like that ?":
A bit late to the party but yes, I have written a free and open source component that implements the Google Place Autocomplete and Google Place Details API's:
It does inherit from the standard TComboBox but you can modify the code to work with any TEdit
https://carbonsoft.co.za/components/
or
https://github.com/RynoCoetzee/TRCGPlaceAutoCompleteCombo
I have a form with a grid with data and some db controls (DBEdit for instance).
When user types inside the DBEdit, Delphi automatically set the record in edit mode. But I dont like this, I want to be able to edit a record only if I programmatically call Table.Edit;
any idea how to prevent this? of course without setting the edit control read-only. I mean a workaround in the data aware components (table) directly.
Set the AutoEdit property of your datasource to false.
DBNavigator provides a nbEdit Button.
Look up TDataSource.AutoEdit property.