Using checkbox in virtual mode listview - delphi

I am learning to make virtual mode listview. So far my problem is I can not use checkbox in the listview. I already read a link from http://delphi-kb.blogspot.com/2011/02/draw-checkboxes-in-virtual-mode.html but I don't see any checkbox. Any idea?

Apparently you have to draw the CheckBoxes yourself when OwnerData is enabled (as mentioned in the article linked in the question).
So you have to set OwnerDraw to True (in addition to OwnerData, the two are independed flags!) and draw the CheckBoxes yourself in the OnCustomDrawItem event.
Update:
It seems that this is not entirely true, the OnCustomDrawItem event is also fired in the case OwnerDraw = False.
http://docwiki.embarcadero.com/VCL/XE2/en/ComCtrls.TListView.OnCustomDrawItem
Update 2:
The code linked in the question only works when OwnerDraw = False and CheckBoxes = True.
Otherwise the VCL doesn't reserve space on the left to draw CheckBoxes.
BTW: You might be better of using a more advanced component like TVirtualTreeView from Mike Lischke.

Related

How to update component Status at Form create?

I had created a simple program which includes many checkboxes and TComboEdit. When an certain checkbox is checked, then an editbox becomes enabled. Some checkbox is checked by default. My problem is when I run the program the unchecked component's edit box are visible too, which should be disabled as the checkbox is not checked at all. But when I check them and uncheck again the edit box disables which it should be. So how to update component's status at form create ? Or any other good way to do it.
so sorry for the grammar mistakes.
Either set the visible property of the edit fields to false in the designer, or do as David Heffernan suggests: Write an OnCreate handler, where you do that in code.

Delphi TRibbon ToolTip for buttons

I am trying to add a ToolTip (or hint as Delphi refers to it) to the buttons on the ribbon. I am using the TRibbon that comes with Delphi XE7. I am developing in the VCL framework.
I did find a Hint property in the Action that is linked to the button on the Ribbon, but I cannot get the Hint to display.
So it seems that the correct answer is to set ShowHint = True on the form.
First, I'd check if the form (and possibly the ribbon) have ShowHint = True.

Disabling editing option on TDBGrid doesn't function

When creating TDBGrid components dynamically at runtime, i can't forbid user to edit values in cells. This is how I am trying to accomplish this type of behaviour:
TDBGrid *DbGrid = new TDBGrid(Owner);
DbGrid->Options = DbGrid->Options >> dgEditing;
When disabling dgEditing in form designer all is functioning correctly. I can't find the difference between these two cases. What should I do to disable edit of DBGrid cells?
The trick is to do this in following way:
DbGrid->Options = TDBGridOptions(DbGrid->Options) >> dgEditing
but I do not know what is the difference.
I have the same problem with the Seattle version of C++Builder in that I am unable to programmatically change whether the DbGrid allows or disallows editing. The DbGrid->Options values CAN be changed without requiring the TDBGridOptions() cast but the DbGrid does not follow what the DbGrid->Options are set to. If they are set in the object inspector for dgEditing enabled, then the DbGrid always allows editing no matter what the state of DbGrid->Options.dgEditing is and if in the object inspector dgEditing is disabled then the DbGrid never allows editing. It at first APPEARS to work (i.e. the highliting of rows vs cells changes). I have tested this using both DbGrid->Options.ToInt() and DbGrid->Options.Contains(dgEditing) to ensure I'm not stumbling over myself.
I finally found a way to make it work.
If you set the dgEditing to true (for the Options of the DBGrid in the Object Inspector), this will let the user edit at any time. Then, set DBGrid->ReadOnly=false when the user should not be allowed to edit.
I did not have any luck trying to set the individual DBGrid->Columns->Items[ii]->ReadOnly=false. The program did not prevent me from doing that, but it did ignore whatever I had in it.
I wrote a special small test program with minimum components and was able to get good results just by setting the dgEditing to true in the object inspector and then changed dgEditing to false when I wanted to prevent the user from editing, but when I put it into my full program, something prevented the DBGrid from working.
The DBGrid->ReadOnly may be a work-around for someone else also.

how to set the tabwidth of the listbox portion of a TComboBox in Delphi

You can easily achieve a multicolumn effect in a listbox by setting the TabWidth property of TListbox. For example, http://delphi.about.com/cs/adptips2000/a/bltip1200_3.htm
I need to do the same in the drop down list of a ComboBox, but comboboxes don't publish any TabWidth property.
Any ideas?
In a comment to this answer advising you to owner-draw the list box items you say:
I'm wondering why I must do that when the required functionality already exists on a listbox
A combo box is actually composed of three native child windows - the combo box itself, an embedded edit, and a list box. You can use the GetComboBoxInfo() function to fill a COMBOBOXINFO structure (i.e. a TComboBoxInfo record) with information about the control, and it will return the 3 HWND elements in it. With that you are able to alter the appearance and behaviour of the list box. In principle.
For the list box to use the tab stops it needs to have the LBS_USETABSTOPS style flag set. Unfortunately this can't be turned on later, the list box has to be created with it. So you could use the functionality only if you were able to turn the style flag on for the list box, which is created during the CreateWindowEx() call for the combo box. AFAICS this can only be done by hooking the CreateWindowEx() call itself, identifying the internal call that creates the list box, and altering the passed style. This means runtime modification of code, and not in your executable but in a Windows DLL.
Owner-drawing the list items looks like it would be much easier.
From what I know there is not so simple way as TabWidth here but you can override Paint method and draw it yourself. Looking at listbox and combobox sources may help.

RichEdit VCL and URLs. Workarounds for OnPaint Issues

My issue is with the thing Delphi progies scare to death - Rich Edit in Windows (XP and pre-XP versions).
Situation:
I have added EM_AUTOURLDETECTION in OnCreate of form. Target -> RichEdit1. Then, I have form, that is "collapsed" after showing form. RichEdit Control is sattic, visible and enabled, but it is "hidden" because form window is collapsed.
I can expand and collapse form, using Button1 and changing forms Constraints and Size properties.
After first time I expand form, the URL inside RichEdit1 control is highlighted. But, after second, third, fourth, etc... times I collapse and expand form, the RichEdit1 Control does not highlight URL anymore.
I have tried EM_SETTEXTMODE messages, also WM_UPDATEUISTATE, also basic WM_TEXT message -> no luck. It sems like this merssage really works ( enables detection ) while sending keyboard strokes ( virtual keycodes ), but not when text has been modified.
Also - I am thinking to rewrite code to make RichEdit Control dynamic. Would this fix the problem?
Maybe solution is to override OnPaint / OnDraw method to avoid highlight ( formatting ) losing when collapsing or expanding form?
Weird is that my Embarcadero Documentation says this function must work in any moment text has been modified. Why it does not work?
Any help appreciated. I am making this Community Wiki because this is common problem and togewther we cam find solution, right? :)
Also - follow-ups and related Question:
Override OnPaint
How to autodetect urls in RichEdit 2.0?
http://www.vbforums.com/archive/index.php/t-59959.html
I am not sure but is the window of the richedit recreated when geing from hide to show? If this is the case you might create your own derived TRichEdit class, override the function that creates the WIndows Handle (TWinControl.CreateHandle) and add EM_AUTOURLDETECTION there.

Resources