Delphi dbgrid with wildcard character - delphi

I have DBGrid. Sometimes, if i change some cell value, it give a wildcard. You can see that in the image.
My question : when this wildcard, it can be appear? How can disable that?

The * is an indicator that your dbgrid is in insert mode.
If you don't want this indicator to appear you can change (the drawing of) it in the OnDrawColumnCell event.
If you use this event you may need to set dbGrid.DefaultDrawing to false.
See also: http://docwiki.embarcadero.com/RADStudio/Seattle/en/Controlling_Grid_Drawing
Another option is to implement your own custom style.
type
TMyStyleWithNoIndicator = class(TCustomStyleServices)
function GetElementDetails(Detail: TThemedGrid): TThemedElementDetails; override;
end;
function TMyStyleWithNoIndicator.GetElementDetails(Detail: TThemedGrid): TThemedElementDetails;
begin
inherited;
//prevent drawing of the insert indicator.
if Detail in [tgIndicatorInsert] then Result.State = Ord(tgCellNormal);
end;
procedure TForm1.Form1Create(Sender: TObject);
begin
TStyleManager.SetStyle(TMyStyleWithNoIndicator.Create);
end;

Related

Delphi : losing focus from parent when clicking on child

I am having a problem with an effect trigger (shadow effect). I did put the trigger to be ismouseover = true. So, when I put the mouse onto a panel (parent), the shadows activate, and it works fine until I start putting some buttons inside the panel (children).
The shadows effect goes off when the mouse is over the children.
So, is there anyway to keep focus on the parents while being focused on the children?
I did try to change the trigger of the effects (from ismouseover to isfocused), but it didn't give any different results.
As said, your design is wrong, then you can remove the trigger and do it manually :
// show or hide shadow effect
procedure TForm2.ShowShadowEffect(AValue: boolean);
begin
if ShadowEffect1.Enabled <> AValue then
ShadowEffect1.Enabled := AValue;
end;
// show when enter on panel
procedure TForm2.Panel1MouseEnter(Sender: TObject);
begin
ShowShadowEffect(True);
end;
// hide when leave the panel
procedure TForm2.Panel1MouseLeave(Sender: TObject);
begin
ShowShadowEffect(False);
end;
// keep visible when over button
procedure TForm2.Button1MouseEnter(Sender: TObject);
begin
ShowShadowEffect(True);
end;

Delphi: Bind a Chart with a DBGrid

I want to bind a Chart with a DBGrid.
Refer to the exhibit.
When I click in the DBGrid on number 3 (X-Axis), then the bar at position three should be highlighted(or a pointer to bar 3).
When I click on number 4 in the Grid then bar 4 is highlighted etc.
I'm using a TDBChart
Is there a way to do this?
Not knowing what the charting component is, cannot provide a working example, but the key which you are looking for is to use the AfterScroll event for the dataset in the grid. Since each row represents a different record, that event is fired when the grid selection moves to the row.
Edit: This doesn't highlight with a box, but does change the color of the value marks at the top of each bar. Hopefully this gets you on your way. MyQuery is what is feeding the datasource
var
savecolor : tcolor;
procedure MyForm.FormShow(Sender:TObject);
begin
...
SaveColor := dbchart1.series[0].marks.items[0].color;
...
end;
procedure MyForm.MyQueryBeforeScroll(DataSet : TDataSet);
begin
dbchart1.series[0].marks.items[MyQuery.recno-1].color := SaveColor;
end;
procedure MyForm.MyQueryAfterScroll(DataSet:TDataSet);
begin
dbchart1.series[0].marks.items[MyQuery.recno-1].color := clRed;
end;

Custom dbgrid and Picklist issue

I'm creating my own DBGRid, and it works fine , except of the pick list. whatever button style is set for the grid, it always shows the inplace editor , neither the pick list nor the ellipse button !
i can not figure the mistake I'm doing :( . here is the relevant code :
function TMyDBGrid.CreateEditor: TInplaceEdit;
begin
result:=TInplaceEdit.Create(self);
end;
function TMyDBGrid.GetEditStyle(ACol, ARow: integer): TEditStyle;
begin
case Columns[ACol].ButtonStyle of
cbsAuto : Result:=esPickList;
cbsNone : result:=esSimple;
cbsEllipsis : result:=esEllipsis;
end;
end;
And the constructor and destructor just call inherited , with the constructor just setting some colors for the grid.
The reason there's no pick list or button is that you are using an TInplaceEdit as the cell editor which does not support the functionality you need.
The TDBGrid uses an TDBGridInplaceEdit that inherits from TInplaceEditList as its in place editor which integrates a TCustomListbox for its drop down list and paints and manages the edit button.

How can I get a TDBLookupComboBox to show what you are typing?

I have a TDBLookupComboBox on my form.
When I put my cursor in it and type, the selection jumps a head to what I've typed (or as close as it can).
However I don't get any indication of what I've typed in the field.
TDBComboBox performs similarly to TDBLookupComboBox however, when I type in the field, the characters I type appear in regular text, and the 'completion' of the selection appears in inverse/selected following the regular text.
Is there a way I can make TDBLookupComboBox perform like TDBComboBox in this respect?
No, you can't make TDBLookupComboBox act like a TDBComboBox (without a bit of hacking).
The problem is that TDBLookupComboBox is used to lookup an index-field (normally a number) from another table. The chosen index is set in the destination-field. When you make TDBLookupComboBox "editable" (like TDBComboBox), you could type in anything, even values not in the source-table. And that shouldn't happen (by design). What index-value would you set in that case in the destination field?
You have several options.
You could "hack" TDBLookupComboBox to override the paint procedure to overwrite the selected text with the not selected (already typed) text. It's not easy. Especially if you want to maintain the functionality correctly. But here is some code where I think I've come close to what you want. Although when typing something that's not in the lookup-dataset it doesn't go any further. (It also doesn't account for right aligned text etc.):
type
TDBLookupComboBox = class(DBCtrls.TDBLookupComboBox)
protected
procedure Paint; override;
procedure KeyPress(var Key: Char); override;
end;
type
TForm1 = class(TForm)
DBLookupComboBox1: TDBLookupComboBox;
//.....
procedure TDBLookupComboBox.Paint;
var
TextPart: String;
begin
inherited;
Canvas.Font := Font;
Canvas.Brush.Color := Color;
// keeps case like the field is drawn
TextPart := Copy(Text, 1, Length(SearchText));
Canvas.TextOut(2, 2, TextPart);
end;
procedure TDBLookupComboBox.KeyPress(var Key: Char);
begin
inherited;
// we need this because paint is already called
// we need to call it again to overwrite the text
invalidate;
end;
It overrides the DBLookupComboBox at the top of your form. You don't have to compile this into a new component. You can just paste it into your form with the DBLookupComboBox. We need to call Paint again after keypress (with invalidate) because paint is already called before coming to that routine.
Another option is to use the TDBComboBox. You can fill the pulldown-items in OnEnter.
procedure TForm1.DBComboBox1Enter(Sender: TObject);
begin
DBComboBox1.Items.Clear;
IBQuery1.First;
while not IBQuery1.EOF do
begin
DBComboBox1.Items.Add(IBQuery1.FieldByName('TESTFIELD').DisplayText);
IBQuery1.Next;
end;
end;
If that's too slow (when entering the combobox) you could also fill the items at opening of the dataset.
Another few options from Jedi-library:
JvDBLookupCombo1
Has a pulldown directly when typing. The original typed text stays in the box.
TJvDBSearchComboBox
Also does what you want but is not connected to a destination datasource. You'll need to set the desired field yourself on OnExit.

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