Delphi TComboBox disable highlight (focused) - delphi

After open form item in TCombobox is highlighted (Blue backgrond on text).
Is it possible disable that.
Tnx all!

You can put this message into OnEnter event of TCombobox object:
// Suppose the combobox control name is ComboBox
procedure TMainForm.ComboBoxEnter(Sender: TObject);
begin
PostMessage(ComboBox.Handle, CB_SETEDITSEL, Cardinal(-1), 0);
end;

Related

How can I show hints for droppeddown TComboBox items in Delphi 10.3.3?

I have to show hints for the dropped down TComboBox items.
For this, I could use the OnMouseMove event to handle the hovering message. It takes the mouse X,Y client coordinates as parameters. If I could determine which is the first item to draw (dropdown list with a vertical scrollbar) then I could determine the item under the cursor using the ItemHeight value.
Is there any Win32 API call of message to get this value? The IDE does not support this information, or I couldn't find it.
One option is to use an cxOwnerDrawXXXX style ComboBox and the OnDrawItem event which tells you when you are drawing a focused item. I used this method myself once to update a static hint in a text box that provides more information on the focused / hovered over item.
Example putting hint text in a StaticText control:
procedure TForm1.ComboBox1CloseUp(Sender: TObject);
begin
StaticText1.Caption := '';
end;
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer; Rect:
TRect; State: TOwnerDrawState);
begin
// Update a hint on a static control
if (odSelected in State) and (Control as TComboBox).DroppedDown then
StaticText1.Caption := 'Hint for value:' + (Control as TComboBox).Items[Index];
// Draw list item
with (Control as TComboBox).Canvas do
begin
FillRect(Rect);
TextOut(Rect.Left, Rect.Top, (Control as TComboBox).Items[Index]);
end;
end;
Could be adapted to activate/show/store a hint instead of updating a static control.

TEdit with clear button [duplicate]

When use TEdit control on the right side stay small icon 'x'. How after click on icon clear TEdit box.
Tnx all!
Delphi provide TClearEditButton to clear the TEdit content. It can be added by right clicking and selecting AddItem - TClearEditButton from the popup menu. It also has a Click procedure overriden in FMX.Edit unit like:
procedure TClearEditButton.Click;
var
EditTmp: TCustomEdit;
begin
inherited Click;
EditTmp := GetEdit;
if EditTmp <> nil then
begin
if EditTmp.Observers.IsObserving(TObserverMapping.EditLinkID) then
if not TLinkObservers.EditLinkEdit(EditTmp.Observers) then
Exit; // Can't change
EditTmp.Text := string.Empty;
if EditTmp.Observers.IsObserving(TObserverMapping.EditLinkID) then
TLinkObservers.EditLinkModified(EditTmp.Observers);
if EditTmp.Observers.IsObserving(TObserverMapping.ControlValueID) then
TLinkObservers.ControlValueModified(EditTmp.Observers);
end;
end;
Which make you don't need to write OnClick event handler for the TClearEditButton unless you want to do some other job along side with clearing the edit.
If you are using a TEditButton then you should write the OnClick event handler like:
procedure TForm1.EditButton1Click(Sender: TObject);
begin
Edit1.Text:= EmptyStr;
end;

How to assign a radiogroup line to a Editbox.text

I am trying to use the lines or text next to the radiogroup's radiobuttons to be assigned to the text of a editbox or any other type of output please :) I am using Delphi 2010
The Items property contains the radio button captions, and the ItemIndex property contains the index of the radio button that is currently selected. For example:
procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
Edit1.Text := RadioGroup1.Items[RadioGroup1.ItemIndex];
end;

How to programatically drop down the TcxDateEdit control calendar?

How do you tell the TcxDateEdit control to dropdown the calendar on let's say a button click?
The only way I could think of is simulating key press, but that's just a backup plan.
TCxDateEdit has a DroppedDown property of type Boolean.
To drop down the calendar in a button OnClick event, you may do as following:
procedure TForm1.Button1Click(Sender: TObject);
begin
cxDateEdit.DroppedDown := True;
end;

TListView doesn't hide selection when using explorer style

In Delphi XE4 if you set HideSelection to true and use an explorer style TListView (when the selection rectangle has a gradient background like Windows Explorer) clicking on another control will not hide the selection rectangle. It will stay there as if nothing has happened - it will not even turn into a gray rectangle like normally when the Listview doesn't have focus.
Is this a Delphi bug or a "feature" of the MS Listview control? Are there any known workarounds or fixes for this? It's really annoying...
This is a feature of the underlying control. The delphi code does nothing with the property beyond passing on the LVS_SHOWSELALWAYS list view style to the underlying control.
Initially I was surprised by your question. I've never seen the behaviour that you describe. Upon closer inspection I realise that is because all my list views are virtual. That is they set OwnerData to True and supply content in response to OnData events. Doing that is the only workaround that I know of.
This "feature" is explained by David, and here is a workaround.
By utilizing the OnExit event to save the selection and set selection to nil, you would mimic the wanted behavior. When the ListView is focused, restore the selection.
To make it react on the mouse, make the ListView focused in the OnMouseEnter event.
Type
TForm1 = class(TForm)
...
private
FSelected: TListItem;
...
end;
procedure TForm1.ListView1Enter(Sender: TObject);
begin
if (ListView1.SelCount = 0) and Assigned(FSelected) then
ListView1.Selected := FSelected;
end;
procedure TForm1.ListView1Exit(Sender: TObject);
begin
FSelected := ListView1.Selected;
if Assigned(FSelected) then ListView1.Selected := Nil;
end;
procedure TForm1.ListView1MouseEnter(Sender: TObject);
begin
ListView1.SetFocus;
end;
Having mentioned this solution, why not go for the simple one, set HideSelection = false, and the selected item will turn gray when unfocused, just like Sertac mentioned in a comment.

Resources